#include #include #include using namespace std; using namespace __gnu_pbds; #define rep(i,a,n) for (int i=(a);i<(n);i++) #define per(i,a,n) for (int i=(n)-1;i>=(a);i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector vi; typedef vector vll; typedef pair pii; typedef pairpll; typedef vector vpii; template T getint() { T x=0,p=1; char ch; do{ch=getchar();}while(ch <= ' '); if(ch=='-')p=-1,ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*p; } mt19937 gen(chrono::system_clock::now().time_since_epoch().count()); templatebool umin(T1 &x,const T2&y){if(x>y)return x=y,true;return false;} templatebool umax(T1 &x,const T2&y){if(x c; for(int x:child){ if(max(dp[x][0],dp[x][1])<0)c.pb(x); } if(c.size()>2)return; if(c.size()==0){ dp[v][0]=b[v]; for(int x:child)umax(dp[v][0],dp[x][0]+b[v]); pair twomax=mp(-llinf,-llinf); for(int x:child){ if(dp[x][0]>twomax.fi){ twomax.se=twomax.fi; twomax.fi=dp[x][0]; }else umax(twomax.se,dp[x][0]); } umax(dp[v][1],twomax.fi+twomax.se+b[v]); } if(c.size()==2){ dp[v][0]=-llinf; dp[v][1]=dp[c[0]][0]+dp[c[1]][0]+b[v]; if(dp[v][1]<0)dp[v][1]=-llinf; } if(c.size()==1){ dp[v][0]=b[v]+dp[c[0]][0]; for(int x:child){ if(x!=c[0])umax(dp[v][1],dp[c[0]][0]+b[v]+dp[x][0]); } } umax(dp[v][1],dp[v][0]); } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(0); int T; cin>>T; while(T--) { int n; cin>>n; rep(i,0,n)dp[i][0]=dp[i][1]=0, g[i].clear(); rep(i,0,n)cin>>a[i]; rep(i,0,n-1){ int x,y; cin>>x>>y; --x;--y; g[x].pb(y); g[y].pb(x); } ld lf=0,rg=maxn; rep(j,0,42){ ld md=(lf+rg)/2; rep(i,0,n)b[i]=a[i]-md; solve(0); if(dp[0][1]>=0)lf=md; else rg=md; } cout.precision(7); cout<