#include <stdio.h>
main()
{
	int t; scanf("%d",&t);
	while(t--)
	{
		int n,arr[400005],ko; scanf("%d",&n);
		for(int a=0; a<n ; a++)
			scanf("%d",&arr[a]);
		for(int a=0; a<n-2 ; a++)
		{
			if((arr[a]+arr[a+1])<=arr[a+2]) {printf("1 2 n\n",n);goto jk;	}
		}
	printf("-1\n");jk:ko++;
	}
}


#include<stdio.h>
main()
{
    int n, t, j, i, a, b, c, x, y, z, sign;
    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        sign=0;
        scanf("%d", &n);
        int array[n];
        for(j=0; j<n; j++)
        {
            scanf("%d", &array[j]);
        }

    for(x=0; x<n; x++)
        {
        for(y=x+1; y<n; y++)
        {
        for(z=y+1; z<n; z++)
        {
            a = array[x];
            b = array[y];
            c = array[z];
            if(a+b<c || a+c<b || b+c<a)
            {
                printf("%d %d %d\n", x+1, y+1, z+1);
                sign = 1;
                break;
            }
        }
        if(sign) break;
        }
        if(sign) break;
        }
        if(!sign) printf("%d\n", -1);

    }

}


#include<stdio.h>
main()
{
    int n, t, j, i, a, b, c, x, y, z, sign;
    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        sign=0;
        scanf("%d", &n);
        int array[n];
        for(j=0; j<n; j++)
        {
            scanf("%d", &array[j]);
        }

    for(x=0; x<n; x++)
        {
        for(y=x+1; y<n; y++)
        {
        for(z=y+1; z<n; z++)
        {
            a = array[x];
            b = array[y];
            c = array[z];
            if(a+b<c || a+c<b || b+c<a)
            {
                printf("%d %d %d\n", x+1, y+1, z+1);
                sign = 1;
                goto brick;
            }
        }
        }
        }
        brick:
        if(!sign) printf("%d\n", -1);

    }

}


#include<stdio.h>
main()
{
    int n, t, j, i, a, b, c, x, y, z, sign;
    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        scanf("%d", &n);
        int array[n];
        for(j=0; j<n; j++)
        {
            scanf("%d", &array[j]);
        }

    for(x=0; x<n; x++)
        {
        for(y=0; y<n; y++)
        {
        for(z=0; z<n; z++)
        {
            a = array[x];
            b = array[y];
            c = array[z];
            if(a+b<c || a+c<b || b+c<a)
            {
                printf("%d %d %d", a, b, c);
                sign = 1;
                break;
            }
        }
        if(sign) break;
        }
        if(sign) break;
        }

    }

}


#include<stdio.h>
main()
{
    int n, t, j, i, a, b, c, x, y, z, sign;
    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        sign = 0;
        scanf("%d", &n);
        int array[n];
        for(j=0; j<n; j++)
        {
            scanf("%d", &array[j]);
        }

        a = array[0];
        b = array[1];
        for(x=2; x<n; x++)
        {
            c = array[x];
            if(a+b <= c)
            {
                printf("%d %d %d\n", 1, 2, x+1);
                sign = 1;
                goto brick;
            }
        }
        brick:
        if(!sign) printf("%d\n", -1);

    }

}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>=1)
    {
        int m=(l+r)/2;
        if(a[m]==k) return m;
        else if(a[m]>k) r=m-1;
        else l=m+1;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=0;i<n-2;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n-1,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i+1,i+2,l+1);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>=3)
    {
        int m=(l+r)/2;
        if(a[m]==k) return m;
        else if(a[m]>k) r=m-1;
        else l=m+1;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=0;i<n-2;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n-1,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i+1,i+2,l+1);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>1)
    {
        int m=(l+r)/2;

         if(a[m]>=k) r=m;
        else l=m;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=1;i<n-1;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i,i+1,l);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>1)
    {
        int m=(l+r)/2;

        else if(a[m]>=k) r=m;
        else l=m;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=0;i<n-2;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n-1,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i+1,i+2,l+1);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>1)
    {
        int m=(l+r)/2;
        if(a[m]==k) return m;
        else if(a[m]>k) r=m-1;
        else l=m+1;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=0;i<n-2;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n-1,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i+1,i+2,l+1);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
long long int a[50000];
int b(int l,int r,long long int k)
{
    while(r-l>1)
    {
        int m=(l+r)/2;

         if(a[m]>=k) r=m;
        else l=m;
    }
    if(a[l]>=k) return l;
    if(a[r]>=k) return r;
    return -1;
}
int main()
{
  int t,i,j,n,k,l;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
          scanf("%lld",&a[i]);
      }
      for(i=0;i<n-2;i++)
      {
          long long int h=a[i]+a[i+1];
          l=b(i+2,n-1,h);
          if(l>0) break;
      }
      if(l>0)
      printf("%d %d %d\n",i+1,i+2,l+1);
      else printf("%d\n",-1);
  }
 return 0;
}


#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	for(int tt=0;tt<t;tt++){
		int n;
		scanf("%d",&n);
		int a[n];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
	if(a[0]+a[1]>a[n-1]){
		printf("-1\n");
	}else{
		printf("1 2 %d\n",n);
	}
	}
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long int t,i;
	scanf("%lld",&t);
	while(t--)
	{
		long long int n;
		scanf("%lld",&n);
		long long int a[n],sum,flag=0,x,y,z,j;
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		sum=a[0]+a[1];
	 /*	for(i=0;i<n;i++)
		{
			sum=a[i]+a[i+1];
			for(j=i+2;j<n;j++)
			{
				if(sum<a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				x=i;
				y=i+1;
				z=j;
				break;
			}
		}*/
		if(sum<a[n-1])
		printf("1 2 %lld\n",n);
		else
		printf("-1\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long int t,i;
	scanf("%lld",&t);
	while(t--)
	{
		long long int n;
		scanf("%lld",&n);
		long long int a[n],sum,flag=0,x,y,z,j;
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		sum=a[0]+a[1];
	 /*	for(i=0;i<n;i++)
		{
			sum=a[i]+a[i+1];
			for(j=i+2;j<n;j++)
			{
				if(sum<a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				x=i;
				y=i+1;
				z=j;
				break;
			}
		}*/
		if(sum<=a[n-1])
		printf("%lld %lld %lld\n",1,2,n);
		else
		printf("-1\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long int t,i;
	scanf("%lld",&t);
	while(t--)
	{
		long long int n;
		scanf("%lld",&n);
		long long int a[n],sum,flag=0,x,y,z,j;
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		sum=a[0]+a[1];
	 /*	for(i=0;i<n;i++)
		{
			sum=a[i]+a[i+1];
			for(j=i+2;j<n;j++)
			{
				if(sum<a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				x=i;
				y=i+1;
				z=j;
				break;
			}
		}*/
		if(sum<a[n-1])
		printf("%lld %lld %lld\n",1,2,n);
		else
		printf("-1\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long int t,i;
	scanf("%lld",&t);
	while(t--)
	{
		long long int n;
		scanf("%lld",&n);
		long long int a[n],sum,flag=0,x,y,z,j;
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		for(i=0;i<n;i++)
		{
			sum=a[i]+a[i+1];
			for(j=i+2;j<n;j++)
			{
				if(sum<a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				x=i;
				y=i+1;
				z=j;
				break;
			}
		}
		if(flag!=1)
		printf("-1\n");
		else
		printf("%lld %lld %lld\n",x+1,y+1,z+1);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long int t,i;
	scanf("%lld",&t);
	while(t--)
	{
		long long int n;
		scanf("%lld",&n);
		long long int a[n],sum,flag=0,x,y,z,j;
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		sum=a[0]+a[1];
	 /*	for(i=0;i<n;i++)
		{
			sum=a[i]+a[i+1];
			for(j=i+2;j<n;j++)
			{
				if(sum<a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
			{
				x=i;
				y=i+1;
				z=j;
				break;
			}
		}*/
		if(sum<=a[n-1])
		printf("1 2 %lld\n",n);
		else
		printf("-1\n");
	}
	return 0;
}


#include<stdio.h>
int main()
{
    long long int t,n,i;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        long long int a[n];
        for(i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
        }
        if(a[1]+a[0]<=a[n-1])
        {
            printf("1 2 %lld\n",n);
        }
        else
            printf("-1\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int linenum;

  scanf("%d", &linenum);

  int len[linenum], *a[linenum];

  for (int i = 0; i < linenum; i++)
  {
    scanf("\n%d", &len[i]);

    a[i] = (int *) malloc(len[i] * sizeof(int));;

    for (int j = 0; j < len[i]; j++)
    {
      getchar();
      scanf("%d", a[i] + j);
    }
  }

  for (int i = 0; i < linenum; i++)
  {
    if (*(a[i]) + *(a[i] + 1) <= *(a[i] + len[i] - 1))
    {
      printf("1 2 %d\n", len[i]);
    }
    else
    {
      printf("-1\n");
    }
  }
}


#include<stdio.h>
int main()
{
   int t, n, u, e, f, g, sum;
   int a[100000];
   int flag=-1;
   scanf("%d", &t);
   while(t--)
   {
      scanf("%d", &n);
      for(u=0;u<n;u++)
      {
         scanf("%d", &a[u]);
      }
      sum=a[0]+a[1];
      if(a[n-1]>=sum)
      {
         e=1;
         f=2;
         printf("%d %d %d",e,f,n );
      }
      else
      {
        printf("%d", flag);
      }
    }
}


#include<stdio.h>
int main()
{
   int t, n, u, e, f, g, sum;
   int a[100000];
   int flag=-1;
   scanf("%d", &t);
   while(t--)
   {
      scanf("%d", &n);
      for(u=0;u<n;u++)
      {
         scanf("%d", &a[u]);
      }
      sum=a[0]+a[1];
      if(a[n-1]>=sum)
      {
         e=1;
         f=2;
         printf("\n %d %d %d",e,f,n );
      }
      else
      {
        printf("\n %d", flag);
      }
    }
}


    #include<stdio.h>

    int main()
    {
            int i, n, t, arr[100000];
            scanf("%d", &t);

            while(t--)
            {
                    scanf("%d", &n);

                    for(i=0; i<n; i++)
                            scanf("%d", &arr[i]);
                    if(arr[0] + arr[1] > arr[n-1]) printf("-1\n");
                    else printf("%d %d %d\n", 1, 2, n);
            }

            return 0;
    }


#include<stdio.h>

int main()
{
        int i, n, t, arr[100000];
        scanf("%d", &t);

        while(t--)
        {
                scanf("%d", &n);

                for(i=0; i<n; i++)
                        scanf("%d", &arr[i]);
                if(arr[0] + arr[1] > arr[n-1]) printf("-1\n");
                else printf("%d %d %d\n", 0, 1, n);
        }

        return 0;
}
$


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=4e5+5;
int n,nu,rt,now,res,_max,a[N],v[N],w[N],vi[N],si[N],nex[N],head[N];
void addedges(int x,int y,int z){
	nex[++now]=head[x],w[now]=z;
	head[x]=now,v[now]=y;
}
double ans,sum,tot,d[N];
void get(int x,int fa){
	si[x]=1;
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa&&!vi[v[i]])
			get(v[i],x),si[x]+=si[v[i]];
	if(_max>max(si[x],nu-si[x]))	_max=max(si[x],nu-si[x]),rt=x;
}
void calc(int x,int fa,int dis){
	sum+=pow(dis,1.5)*a[x];
	d[x]=1.5*pow(dis,0.5)*a[x];
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa){
			calc(v[i],x,dis+w[i]);
			d[x]+=d[v[i]];
		}
}
void dfs(int x){
	sum=0,nu=si[x],_max=nu+1,get(x,x),vi[rt]=1;
	for(int i=head[rt];i;i=nex[i])
		calc(v[i],rt,w[i]),tot+=d[v[i]];
	if(ans>sum)	ans=sum,res=rt;
	for(int i=head[rt];i;i=nex[i])
		if(tot-d[v[i]]*2<0&&!vi[v[i]])	dfs(v[i]);
}
int main(){
	//freopen("1.in","r",stdin);
	n=read(),ans=LLONG_MAX;
	for(int i=1;i<=n;i++)	a[i]=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read(),z=read();
		addedges(x,y,z),addedges(y,x,z);
	}
	si[1]=n,dfs(1);
	printf("%d %.6lf\n",res,ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 2e5 + 5;
int n , root , ans1;
int size[N] , w[N];
bool vis[N];
double ans2 = 1e18 , sum , sumd;
double d[N];
struct Edge
{
	int to , dis; Edge *nxt;
	Edge(int to = 0,int dis = 0,Edge *nxt = NULL) : to(to) , dis(dis) , nxt(nxt) {}
} *head[N] , pool[N << 1] , *tail = pool;
inline void add(int u,int v,int w) { head[u] = new (tail ++) Edge(v,w,head[u]);}
void dfs(int x,int fa,int S)
{
	size[x] = 1; int maxn = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(vis[to] || to == fa) continue;
		dfs(to,x,S);
		size[x] += size[to];
		maxn = max(maxn,size[to]);
	}
	maxn = max(maxn,S - size[x]);
	if(maxn <= (S >> 1)) root = x;
}
void calc(int x,int fa,int o,int z)
{
	sum += pow(z,1.5) * w[x]; d[o] += pow(z,0.5) * 1.5 * w[x];
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(to == fa) continue;
		calc(to,x,o,z + i -> dis);
	}
}
void dfs(int x,int S)
{
	if(vis[x]) return;
	dfs(x,0,S); x = root; dfs(x,0,S);
	vis[x] = 1;
	sum = sumd = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		d[to] = 0; calc(to,x,to,i -> dis); sumd += d[to];
	}
	if(sum < ans2) ans1 = x , ans2 = sum;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(sumd - d[to] * 2 >= 0) continue;
		dfs(to,size[to]);
		return ;
	}
}
int main()
{
	n = read();
	for(int i = 1;i <= n;i ++) w[i] = read();
	for(int i = 1 , u , v , w;i < n;i ++)
	{
		u = read(); v = read(); w = read();
		add(u,v,w); add(v,u,w);
	}
	dfs(1,n);
	printf("%d %.10f\n",ans1,ans2);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 2e5 + 5;
int n , root , ans1;
int size[N] , w[N];
bool vis[N];
double ans2 = 1e20 , sum , sumd;
double d[N];
struct Edge
{
	int to , dis; Edge *nxt;
	Edge(int to = 0,int dis = 0,Edge *nxt = NULL) : to(to) , dis(dis) , nxt(nxt) {}
} *head[N] , pool[N << 1] , *tail = pool;
inline void add(int u,int v,int w) { head[u] = new (tail ++) Edge(v,w,head[u]);}
void dfs(int x,int fa,int S)
{
	size[x] = 1; int maxn = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(vis[to] || to == fa) continue;
		dfs(to,x,S);
		size[x] += size[to];
		maxn = max(maxn,size[to]);
	}
	maxn = max(maxn,S - size[x]);
	if(maxn <= (S >> 1)) root = x;
}
void calc(int x,int fa,int o,int z)
{
	sum += pow(z,1.5) * w[x]; d[o] += pow(z,0.5) * 1.5 * w[x];
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(to == fa) continue;
		calc(to,x,o,z + i -> dis);
	}
}
void dfs(int x,int S)
{
	if(vis[x]) return;
	dfs(x,0,S); x = root; dfs(x,0,S);
	vis[x] = 1;
	sum = sumd = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		d[to] = 0; calc(to,x,to,i -> dis); sumd += d[to];
	}
	if(sum < ans2) ans1 = x , ans2 = sum;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(sumd - d[to] * 2 >= 0) continue;
		dfs(to,size[to]);
		return ;
	}
}
int main()
{
	n = read();
	for(int i = 1;i <= n;i ++) w[i] = read();
	for(int i = 1 , u , v , w;i < n;i ++)
	{
		u = read(); v = read(); w = read();
		add(u,v,w); add(v,u,w);
	}
	dfs(1,n);
	printf("%d %.10f\n",ans1,ans2);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 2e5 + 5;
int n , root , ans1;
int size[N] , w[N];
bool vis[N];
double ans2 = 1e18 , sum , sumd;
double d[N];
struct Edge
{
	int to , dis; Edge *nxt;
	Edge(int to = 0,int dis = 0,Edge *nxt = NULL) : to(to) , dis(dis) , nxt(nxt) {}
} *head[N] , pool[N << 1] , *tail = pool;
inline void add(int u,int v,int w) { head[u] = new (tail ++) Edge(v,w,head[u]);}
void dfs(int x,int fa,int S)
{
	size[x] = 1; int maxn = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(vis[to] || to == fa) continue;
		dfs(to,x,S);
		size[x] += size[to];
		maxn = max(maxn,size[to]);
	}
	maxn = max(maxn,S - size[x]);
	if(maxn <= (S >> 1)) root = x;
}
void calc(int x,int fa,int o,int z)
{
	sum += pow(z,1.5) * w[x]; d[o] += pow(z,0.5) * 1.5 * w[x];
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(to == fa) continue;
		calc(to,x,o,z + i -> dis);
	}
}
void dfs(int x,int S)
{
	if(vis[x]) return;
	dfs(x,0,S); x = root; dfs(x,0,S);
	vis[x] = 1;
	sum = sumd = 0;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		d[to] = 0; calc(to,x,to,i -> dis); sumd += d[to];
	}
	if(sum < ans2) ans1 = x , ans2 = sum;
	for(Edge *i = head[x];i;i = i -> nxt)
	{
		int to = i -> to;
		if(sumd - 2 * d[to] >= 0) continue;
		dfs(to,size[to]);
		return ;
	}
}
int main()
{
	n = read();
	for(int i = 1;i <= n;i ++) w[i] = read();
	for(int i = 1 , u , v , w;i < n;i ++)
	{
		u = read(); v = read(); w = read();
		add(u,v,w); add(v,u,w);
	}
	dfs(1,n);
	printf("%d %.10f\n",ans1,ans2);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666;
int n,w[N];int ans1;double ans2=1e100,cur,ans[N];bool gg[N];
int sz[N],T;vector<Pii>e[N];
void getsz(int u,int fa){
	sz[u]=1;rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getsz(e[u][i].fi,u),sz[u]+=sz[e[u][i].fi];
}
void getcen(int u, int fa, Pii &res){
	int mx=T-sz[u];
	rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getcen(e[u][i].fi,u,res),umax(mx,sz[e[u][i].fi]);
//	if(mx==-1)cerr<<T<<' '<<sz[u]<<endl;
	res=min(res,Pii(mx,u));
}
void getans(int u, int fa, ll dis, int bel){
	cur+=w[u]*dis*sqrt(dis);ans[bel]+=w[u]*sqrt(dis);
	rep(i,0,SZ(e[u])-1)if(e[u][i].fi!=fa)
		getans(e[u][i].fi,u,dis+e[u][i].se,bel);
}
void solve(int rt){
	getsz(rt,0);T=sz[rt];Pii res(1e9,rt);getcen(rt,0,res);
	assert(res.fi<=T/2);rt=res.se;gg[rt]=1;cur=0;double sum=0;
	cerr<<rt<<' '<<T<<' '<<res.fi<<endl;
	rep(i,0,SZ(e[rt])-1){
		ans[e[rt][i].fi]=0,getans(e[rt][i].fi,rt,e[rt][i].se,e[rt][i].fi),
		sum+=ans[e[rt][i].fi];
	}
	if(cur<ans2)ans2=cur,ans1=rt;
	rep(i,0,SZ(e[rt])-1)if(ans[e[rt][i].fi]*2>sum&&!gg[e[rt][i].fi]){
		solve(e[rt][i].fi);break;
	}
}
int main() {//freopen("1.in","r",stdin);
	read(n);rep(i,1,n)read(w[i]);
	rep(i,1,n-1){
		int u,v,w;read(u);read(v);read(w);
		e[u].pb(Pii(v,w));e[v].pb(Pii(u,w));
	}
	solve(1);printf("%d %.11lf\n",ans1,ans2);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666;
int n,w[N];int ans1;double ans2=1e18,cur,ans[N];bool gg[N];
int sz[N],T;vector<Pii>e[N];
void getsz(int u,int fa){
	sz[u]=1;rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getsz(e[u][i].fi,u),sz[u]+=sz[e[u][i].fi];
}
void getcen(int u, int fa, Pii &res){
	int mx=T-sz[u];
	rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getcen(e[u][i].fi,u,res),umax(mx,sz[e[u][i].fi]);
//	if(mx==-1)cerr<<T<<' '<<sz[u]<<endl;
	res=min(res,Pii(mx,u));
}
void getans(int u, int fa, ll dis, int bel){
	cur+=w[u]*dis*sqrt(dis);ans[bel]+=w[u]*sqrt(dis);
	rep(i,0,SZ(e[u])-1)if(e[u][i].fi!=fa)
		getans(e[u][i].fi,u,dis+e[u][i].se,bel);
}
void solve(int rt){
	getsz(rt,0);T=sz[rt];Pii res(1e9,rt);getcen(rt,0,res);
	assert(res.fi<=T/2);rt=res.se;gg[rt]=1;cur=0;double sum=0;
	cerr<<rt<<' '<<T<<' '<<res.fi<<endl;
	rep(i,0,SZ(e[rt])-1){
		ans[e[rt][i].fi]=0,getans(e[rt][i].fi,rt,e[rt][i].se,e[rt][i].fi),
		sum+=ans[e[rt][i].fi];
	}
	if(cur<ans2)ans2=cur,ans1=rt;
	rep(i,0,SZ(e[rt])-1)if(ans[e[rt][i].fi]*2>sum&&!gg[e[rt][i].fi]){
		solve(e[rt][i].fi);break;
	}
}
int main() {//freopen("1.in","r",stdin);
	read(n);rep(i,1,n)read(w[i]);
	rep(i,1,n-1){
		int u,v,w;read(u);read(v);read(w);
		e[u].pb(Pii(v,w));e[v].pb(Pii(u,w));
	}
	solve(1);printf("%d %.11lf\n",ans1,ans2);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666;
int n,w[N];int ans1;double ans2=1e18,cur,ans[N];bool gg[N];
int sz[N],T;vector<Pii>e[N];
void getsz(int u,int fa){
	sz[u]=1;rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getsz(e[u][i].fi,u),sz[u]+=sz[e[u][i].fi];
}
void getcen(int u, int fa, Pii &res){
	int mx=T-sz[u];
	rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getcen(e[u][i].fi,u,res),umax(mx,sz[e[u][i].fi]);
	res=min(res,Pii(mx,u));
}
void getans(int u, int fa, ll dis, int bel){
	cur+=w[u]*dis*sqrt(dis);ans[bel]+=w[u]*sqrt(dis);
	rep(i,0,SZ(e[u])-1)if(e[u][i].fi!=fa)
		getans(e[u][i].fi,u,dis+e[u][i].se,bel);
}
void solve(int rt){
	getsz(rt,0);int T=sz[rt];Pii res(1e9,rt);getcen(rt,0,res);
	rt=res.se;gg[rt]=1;cur=0;double sum=0;
//	cerr<<rt<<endl;
	rep(i,0,SZ(e[rt])-1){
		ans[e[rt][i].fi]=0,getans(e[rt][i].fi,rt,e[rt][i].se,e[rt][i].fi),
		sum+=ans[e[rt][i].fi];
	}
	if(cur<ans2)ans2=cur,ans1=rt;
	rep(i,0,SZ(e[rt])-1)if(ans[e[rt][i].fi]*2>sum&&!gg[e[rt][i].fi]){
		solve(e[rt][i].fi);break;
	}
}
int main() {
	read(n);rep(i,1,n)read(w[i]);
	rep(i,1,n-1){
		int u,v,w;read(u);read(v);read(w);
		e[u].pb(Pii(v,w));e[v].pb(Pii(u,w));
	}
	solve(1);printf("%d %.11lf\n",ans1,ans2);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666;
int n,w[N];int ans1;double ans2=1e18,cur,ans[N];bool gg[N];
int sz[N],T;vector<Pii>e[N];
void getsz(int u,int fa){
	sz[u]=1;rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getsz(e[u][i].fi,u),sz[u]+=sz[e[u][i].fi];
}
void getcen(int u, int fa, Pii &res){
	int mx=T-sz[u];
	rep(i,0,SZ(e[u])-1)if(!gg[e[u][i].fi]&&e[u][i].fi!=fa)
		getcen(e[u][i].fi,u,res),umax(mx,sz[e[u][i].fi]);
	res=min(res,Pii(mx,u));
}
void getans(int u, int fa, ll dis, int bel){
	cur+=w[u]*dis*sqrt(dis);ans[bel]+=w[u]*sqrt(dis);
	rep(i,0,SZ(e[u])-1)if(e[u][i].fi!=fa)
		getans(e[u][i].fi,u,dis+e[u][i].se,bel);
}
void solve(int rt){
	getsz(rt,0);int T=sz[rt];Pii res(1e9,rt);getcen(rt,0,res);
	assert(res.fi<=T/2);rt=res.se;gg[rt]=1;cur=0;double sum=0;
//	cerr<<rt<<endl;
	rep(i,0,SZ(e[rt])-1){
		ans[e[rt][i].fi]=0,getans(e[rt][i].fi,rt,e[rt][i].se,e[rt][i].fi),
		sum+=ans[e[rt][i].fi];
	}
	if(cur<ans2)ans2=cur,ans1=rt;
	rep(i,0,SZ(e[rt])-1)if(ans[e[rt][i].fi]*2>sum&&!gg[e[rt][i].fi]){
		solve(e[rt][i].fi);break;
	}
}
int main() {
	read(n);rep(i,1,n)read(w[i]);
	rep(i,1,n-1){
		int u,v,w;read(u);read(v);read(w);
		e[u].pb(Pii(v,w));e[v].pb(Pii(u,w));
	}
	solve(1);printf("%d %.11lf\n",ans1,ans2);
	return 0;
}


#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 200005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,head[MAX],cnt=0,v[MAX];
struct edge{
	int next,to,value;
}a[MAX<<1];
void add(int x,int y,int z)
{
	a[++cnt].next=head[x];
	a[cnt].to=y;
	a[cnt].value=z;
	head[x]=cnt;
}
int vst[MAX],root,sz[MAX],allsz;
void getroot(int x,int f)
{
	sz[x]=1;
	int tp=0;
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		if(vst[t]||t==f) continue;
		getroot(t,x);
		sz[x]+=sz[t];
		tp=max(tp,sz[t]);
	}
	tp=max(tp,allsz-sz[x]);
	if(tp<=allsz/2) root=x;
}
void getsz(int x,int f)
{
	sz[x]=1;
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		if(vst[t]||t==f) continue;
		getsz(t,x);
		sz[x]+=sz[t];
	}
}
int ansid;
double dis[MAX],sm,sm2,ans=INF;
void dfs(int x,int f,int tp,int d)
{
	sm+=pow(d,1.5)*v[x];dis[tp]+=pow(d,0.5)*1.5*v[x];
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		if(t==f) continue;
		dfs(t,x,tp,d+a[i].value);
	}
}
void divide(int x)
{
	if(vst[x]) return;
	vst[x]=1;getsz(x,0);
	sm=sm2=0;
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		dis[t]=0;
		dfs(t,x,t,a[i].value);
		sm2+=dis[t];
	}
	if(sm<ans) ans=sm,ansid=x;
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		if(sm2-dis[t]*2<0)
		{
			allsz=sz[t];getroot(t,0);
			divide(root);
			break;
		}
	}
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		v[i]=read();
	int x,y,z;
	for(int i=1;i<n;i++)
		x=read(),y=read(),z=read(),add(x,y,z),add(y,x,z);
	allsz=n;getroot(1,0);
	divide(root);
	printf("%d %.10lf",ansid,ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long llg;
const llg MN=200009;
struct node{llg dta;long double wgh;node *nxt;}tree[MN];
llg t,nw,p1,p2,len[MN],bok[MN],cnt,ll,rr,mid,mid1,bk[MN],n,x,y,mid2;
long double mx,z,ans,dta1,dta2,w[MN],dta3;
const long double inf=99999999999999999;
void bd(llg c,llg D,long double e){
	node *q=&tree[c],*p=new node;
	if(q->nxt==NULL) p->nxt=NULL,q->nxt=p,p->dta=D,p->wgh=e;
	else p->nxt=q->nxt,q->nxt=p,p->dta=D,p->wgh=e;
}
llg gi(){
	char c=getchar();llg ans1=0,ans2=1;
	while(c<'0'||c>'9'){if(c=='-') ans2=-1;c=getchar();}
	while(c>='0'&&c<='9') ans1=ans1*10+c-'0',c=getchar();
	return ans1*ans2;
}
void dfs(llg p,llg f,long double l){
	ans+=w[p]*sqrt(l*l*l);
	node *q=tree[p].nxt;
	while(q!=NULL){
		if(q->dta!=f) dfs(q->dta,p,l+q->wgh);
		q=q->nxt;
	}
}
void dfs2(llg p,llg f,long double l){
	if(l>mx) mx=l,p1=p;
	node *q=tree[p].nxt;
	while(q!=NULL){
		if(q->dta!=f&&!bok[q->dta]) dfs2(q->dta,p,l+q->wgh);
		q=q->nxt;
	}
}
void dfs3(llg p,llg f,long double l){
	if(l>mx) mx=l,p2=p; len[p]=l;
	node *q=tree[p].nxt;
	while(q!=NULL){
		if(q->dta!=f&&!bok[q->dta]) dfs3(q->dta,p,l+q->wgh);
		q=q->nxt;
	}
}
void dfs4(llg p,llg f){
	bk[++cnt]=p,bok[p]=1;
	node *q=tree[p].nxt;
	while(q!=NULL){
		if(q->dta!=f&&!bok[q->dta]&&len[q->dta]<len[p]) dfs4(q->dta,p);
		q=q->nxt;
	}
}
void findd(){
	mx=0;
	dfs2(nw,0,0);
	mx=0;
	dfs3(p1,0,0);
	cnt=0;
	dfs4(p2,0);
}
void work(){
	ll=1,rr=cnt;
	while(ll<rr){
		if(rr-ll+1<=5){
			llg book=0;
			for(int i=ll;i<=rr;i++){
				ans=0,dfs(bk[i],0,0);
				if(book==0||book>ans) book=ans,ll=i;
			}
			break;
		}
		mid=(ll+rr)/2,mid1=(mid+ll)/2,mid2=(mid+rr)/2;
		if(mid1==mid) mid++;
		ans=0,dfs(bk[mid],0,0),dta1=ans;
		ans=0,dfs(bk[mid1],0,0),dta2=ans;
		ans=0,dfs(bk[mid2],0,0),dta3=ans;
		if(dta1<dta2) ll=mid1;
		if(dta1<dta3) rr=mid2;
	}
	bok[bk[ll]]=0,nw=bk[ll];
}
int main(){
	freopen("route.in","r",stdin);
	freopen("route.out","w",stdout);
	cout.setf(ios::fixed);
	cout.precision(10);
	n=gi(),nw=1;
	for(int i=1;i<=n;i++) cin>>w[i];
	for(int i=1;i<n;i++) x=gi(),y=gi(),z=gi(),bd(x,y,z),bd(y,x,z);
	while(1){
		findd(),work();
		node *q=tree[nw].nxt;int flag=0;
		while(q!=NULL){
			if(!bok[q->dta]){flag=1;break;}
			q=q->nxt;
		}
		if(flag) continue;
		break;
	}
	ans=0,dfs(nw,0,0);
	cout<<nw<<' '<<ans;
	return 0;
}
/*
5
3 1 2 6 5
1 2 3
2 3 1
4 3 9
5 3 1
*/


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAXN = 2e5 + 5;

int N, w[MAXN];
struct node { int v, next, k; } E[MAXN << 1]; int head[MAXN], Elen;
void add(int u, int v, int k) { ++Elen, E[Elen].v = v, E[Elen].next = head[u], head[u] = Elen, E[Elen].k = k; }

bool vis[MAXN];
int Sum, Rt, Maxpart, siz[MAXN];
void getRt(int u, int ff) {
    siz[u] = 1; int maxpart = 0;
    for (int i = head[u]; i; i = E[i].next) if (!vis[E[i].v] && E[i].v != ff) {
        getRt(E[i].v, u), siz[u] += siz[E[i].v], maxpart = max(maxpart, siz[E[i].v]);
    }
    maxpart = max(maxpart, Sum - siz[u]);
    if (maxpart < Maxpart) Maxpart = maxpart, Rt = u;
}
int dep[MAXN];
double f[MAXN], h[MAXN], hans = 1e100;
int ans;
void dfs(int u, int ff) {
    //printf("dep[%d]=%d\n", u, dep[u]);
    f[u] = pow(dep[u], 0.5) * w[u], h[u] = pow(dep[u], 1.5) * w[u];
    for (int i = head[u]; i; i = E[i].next) if (E[i].v != ff) {
        dep[E[i].v] = dep[u] + E[i].k, dfs(E[i].v, u);
        f[u] += f[E[i].v], h[u] += h[E[i].v];
    }
    //printf("f[%d]=%.2f,h[%d]=%.2f\n", u, f[u], u, h[u]);
}
void Solve() {
    //printf("Solve(%d)\n", Rt);
    vis[Rt] = 1, dep[Rt] = 0, dfs(Rt, 0); int mxson = 0;
    //printf("h[%d]=%.2f\n", Rt, h[Rt]);
    for (int i = head[Rt]; i; i = E[i].next) if (!vis[E[i].v]) {
        //printf("(%d)%.2f\n", E[i].v, -f[E[i].v] + f[Rt] - f[E[i].v]);
        if (-f[E[i].v] + f[Rt] - f[E[i].v] < 0) mxson = E[i].v;
    }
    if (h[Rt] < hans) ans = Rt, hans = h[Rt];
    if (mxson) Maxpart = 1e9, Sum = siz[Rt], Rt = 0, getRt(mxson, 0), Solve();
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    #endif
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) scanf("%d", &w[i]);
    int u, v, k;
    for (int i = 1; i < N; ++i) scanf("%d%d%d", &u, &v, &k), add(u, v, k), add(v, u, k);
    Sum = N, Maxpart = 1e9, getRt(1, 0);
    Solve();
    printf("%d %.8f\n", ans, hans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int w[N];
int Head[N],Next[N<<1],Adj[N<<1],Weight[N<<1],tot=0;
void addedge(int u,int v,int w){
	Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v,Weight[tot]=w;
	Next[++tot]=Head[v],Head[v]=tot,Adj[tot]=u,Weight[tot]=w;
}
int S=0,rt,mn;bool vis[N];
void init(){S=0,rt=0,mn=1<<30;}
void getsz(int x,int f){
	++S;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f&&(!vis[Adj[e]])) getsz(Adj[e],x);
}
int size[N];
void getrt(int x,int f){
	size[x]=1;int mx=0;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f&&(!vis[Adj[e]])){
			getrt(Adj[e],x);
			size[x]+=size[Adj[e]];
			mx=max(mx,size[Adj[e]]);
		}
	mx=max(mx,S-size[x]);
	if (mx<mn) mn=mx,rt=x;
}
double sd[N],sum,sumd;
void calc(int x,int r,int f,int dep){
	sum+=(double)sqrt(dep)*dep*w[x];
	sumd+=1.5*sqrt((double)dep)*w[x];
	sd[r]+=1.5*w[x]*sqrt((double)dep);
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f) calc(Adj[e],r,x,dep+Weight[e]);
}
int ans1;double ans2=1e18;
void solve(int x){
	vis[x]=true;sum=sumd=0;
	for (int e=Head[x];e;e=Next[e])
		sd[Adj[e]]=0,calc(Adj[e],Adj[e],x,Weight[e]);
	if (sum<ans2) ans2=sum,ans1=x;
	for (int e=Head[x];e;e=Next[e])
		if ((!vis[Adj[e]])&&(sumd-2*sd[Adj[e]]<0)){
			init();getsz(Adj[e],x);
			getrt(Adj[e],x);solve(rt);
		}
}
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&w[i]);
	for (int i=1;i<n;i++){
		int x,y,z;scanf ("%d%d%d",&x,&y,&z);
		addedge(x,y,z);
	}
	init();S=n;getrt(1,0);solve(rt);
	printf ("%d %.9f",ans1,ans2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int gi()
{
	char c=getchar(); int x=0;
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	return x;
}
const int N=2e5+5,Inf=1<<30;
int n,w[N],head[N],nxt[N<<1],to[N<<1],wei[N<<1],size[N],rt,mn,sum,ansid;
double ans=1e19,now,df,sdf[N]; bool del[N];
void addedge(int u, int v, int w, int now)
{
	nxt[now]=head[u], head[u]=now, to[now]=v, wei[now]=w;
}
void getsize(int u, int fa)
{
	size[u]=1;
	int mx=0;
	for(int e=head[u];e;e=nxt[e]) if(to[e]!=fa&&!del[to[e]])
	{
		getsize(to[e],u),size[u]+=size[to[e]];
		if(size[to[e]]>mx) mx=size[to[e]];
	}
	mx=max(mx,sum-mx);
	if(mx<mn) mn=mx,rt=u;
}
void deal(int x, int u, int fa, double d)
{
	now+=sqrt(d)*d*w[u],sdf[x]+=sqrt(d)/3*2*w[u];
	for(int e=head[u];e;e=nxt[e]) if(to[e]!=fa) deal(x,to[e],u,d+wei[e]);
}
void dfs(int u)
{
	del[u]=true;
	now=df=0.0;
	for(int e=head[u];e;e=nxt[e]) sdf[to[e]]=0.0,deal(to[e],to[e],u,wei[e]),df+=sdf[to[e]];
	if(now<ans) ans=now,ansid=u;
	for(int e=head[u];e;e=nxt[e]) if(df-sdf[to[e]]*2<0&&!del[to[e]])
		sum=size[to[e]],mn=Inf,rt=0,getsize(to[e],u),dfs(rt);
}
int main()
{
	n=gi();
	for(int i=1;i<=n;++i) w[i]=gi();
	for(int i=1;i<n;++i)
	{
		int u=gi(),v=gi(),w=gi();
		addedge(u,v,w,i*2-1);
		addedge(v,u,w,i*2);
	}
	sum=n,mn=Inf,getsize(1,0),dfs(rt);
	printf("%d %.8lf",ansid,ans);
}


#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

struct e
{
	int to;double val;
	e(int t=0,double v=0):to(t),val(v){}
};vector<e> ed[400000];

double w[400000];
int sz[400000],maxsz[400000];double dis[400000];
bool ban[400000];
vector<int> all_nd;
void dfs_bas(int u,int f)
{
	if(ban[u])return;
	all_nd.push_back(u);
	sz[u]=1,maxsz[u]=0;int maxv=0;
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dfs_bas(v,u);
		sz[u]+=sz[v];maxsz[u]=max(maxsz[u],sz[v]);
	}
}

double der[400000];
double dfs_calc(int u,int f)
{
	der[u]=w[u]*1.5*pow(dis[u],0.5);double sum=w[u]*pow(dis[u],1.5);
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dis[v]=dis[u]+ed[u][i].val;sum+=dfs_calc(v,u);der[u]+=der[v];
	}
	return sum;
}
double ans;int pos;
void work(int u)
{
	int rt=0;dfs_bas(u,0);
	for(int i=0;i<all_nd.size();i++)if(max(sz[u]-sz[all_nd[i]],maxsz[all_nd[i]])<=(sz[u]>>1))rt=all_nd[i];
	dis[rt]=0;double sum=dfs_calc(rt,0);
	if(ans>sum){ans=sum,pos=rt;}
	ban[rt]=1;double sumd=der[rt];
	//printf("%d\n",rt);
	for(int i=0;i<ed[rt].size();i++)
	{
		int v=ed[rt][i].to;if(!ban[v]&&sumd-2*dis[v]<0){work(v);break;}
	}
}

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lf",&w[i]);
	for(int i=1,x=0,y=0;i<n;i++)
	{
		double v=0;scanf("%d%d%lf",&x,&y,&v);ed[x].push_back(e(y,v)),ed[y].push_back(e(x,v));
	}
	ans=1e18;work(1);printf("%d %.10lf",pos,ans);return 0;
}


/*
	一条链的话显然可以三分 (找中点, 看两边的值哪个小)

*/
#include <bits/stdc++.h>
#define N 200005

using namespace std;

int n, wp;
int c[N];

double ans = 1e18;

vector<pair<int, int> > g[N];

inline int read() {
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int root, Size, mSize, siz[N];
double dir, sum, sumd[N];
bool vis[N];

void getRoot(int u, int fa) {
	siz[u] = 1;
	for(int i = g[u].size() - 1, v; ~i; --i) {
		v = g[u][i].first;
		if(v == fa || vis[v]) continue;
		getRoot(v, u), siz[u] += siz[v];
	}
	if(max(siz[u], Size - siz[u]) < mSize) {
		mSize = max(siz[u], Size - siz[u]);
		root = u;
	}
}

void getAns(int u, int fa, double dist) {
	sum += sqrt(dist) * dist * c[u];
	for(int i = g[u].size() - 1, v; ~i; --i) {
		v = g[u][i].first;
		if(v == fa) continue;
		getAns(v, u, dist + g[u][i].second);
	}
}
double getDir(int u, int fa, double dist) {
	double res = 1.5 * sqrt(dist) * c[u];
	for(int i = g[u].size() - 1, v; ~i; --i) {
		v = g[u][i].first;
		if(v == fa || vis[v]) continue;
		res += getDir(v, u, dist + g[u][i].second);
	}
	return res;
}

void solve(int u) {
	mSize = N;
	getRoot(u, u);
	vis[u = root] = true;

	sum = 0, getAns(u, u, 0);
	if(sum < ans) ans = sum, wp = u;

	dir = 0;
	for(int i = g[u].size() - 1, v; ~i; --i) {
		v = g[u][i].first;
		if(vis[v]) continue;
		sumd[v] = getDir(v, u, 0);
		dir += sumd[v];
	}
	for(int i = g[u].size() - 1, v; ~i; --i) {
		v = g[u][i].first;
		if(vis[v] || dir - 2 * sumd[v] > 0) continue;
		Size = siz[v];
		solve(v);
		break;
	}
}

int main() {
	n = read();
	for(int i = 1; i <= n; ++i)
		c[i] = read();
	for(int i = 1, u, v, w; i < n; ++i) {
		u = read(), v = read(), w = read();
		g[u].push_back(make_pair(v, w));
		g[v].push_back(make_pair(u, w));
	}

	Size = n;
	solve(1);

	printf("%d %.8lf", wp, ans);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

struct e
{
	int to;double val;
	e(int t=0,double v=0):to(t),val(v){}
};vector<e> ed[400000];

double w[400000];
int sz[400000],maxsz[400000];double dis[400000];
bool ban[400000];
vector<int> all_nd;
void dfs_bas(int u,int f)
{
	if(ban[u])return;
	all_nd.push_back(u);
	sz[u]=1,maxsz[u]=0;int maxv=0;
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dfs_bas(v,u);
		sz[u]+=sz[v];maxsz[u]=max(maxsz[u],sz[v]);
	}
}

double der[400000];
double dfs_calc(int u,int f)
{
	der[u]=w[u]*1.5*pow(dis[u],0.5);double sum=w[u]*pow(dis[u],1.5);
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dis[v]=dis[u]+ed[u][i].val;sum+=dfs_calc(v,u);der[u]+=der[v];
	}
	return sum;
}
double ans;int pos;
void work(int u)
{
	int rt=0;dfs_bas(u,0);
	for(int i=0;i<all_nd.size();i++)if(max(sz[u]-sz[all_nd[i]],maxsz[all_nd[i]])<=(sz[u]>>1))rt=all_nd[i];
	dis[rt]=0;double sum=dfs_calc(rt,0);
	if(ans>sum){ans=sum,pos=rt;}
	ban[rt]=1;double sumd=der[rt];
	//printf("%d\n",rt);
	for(int i=0;i<ed[rt].size();i++)
	{
		int v=ed[rt][i].to;if(!ban[v]&&sumd-2*dis[v]<0){work(v);break;}
	}
}

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lf",&w[i]);
	for(int i=1,x=0,y=0;i<n;i++)
	{
		double v=0;scanf("%d%d%lf",&x,&y,&v);ed[x].push_back(e(y,v)),ed[y].push_back(e(x,v));
	}
	ans=1e9;work(1);printf("%d %.10lf",pos,ans);return 0;
}


#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

struct e
{
	int to;double val;
	e(int t=0,double v=0):to(t),val(v){}
};vector<e> ed[400000];

double w[400000];
int sz[400000],maxsz[400000];double dis[400000];
bool ban[400000];
vector<int> all_nd;
void dfs_bas(int u,int f)
{
	if(ban[u])return;
	all_nd.push_back(u);
	sz[u]=1,maxsz[u]=0;int maxv=0;
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dfs_bas(v,u);
		sz[u]+=sz[v];maxsz[u]=max(maxsz[u],sz[v]);
	}
}

double der[400000];
double dfs_calc(int u,int f)
{
	der[u]=w[u]*1.5*pow(dis[u],0.5);double sum=w[u]*pow(dis[u],1.5);
	for(int i=0;i<ed[u].size();i++)
	{
		int v=ed[u][i].to;if(v==f)continue;
		dis[v]=dis[u]+ed[u][i].val;sum+=dfs_calc(v,u);der[u]+=der[v];
	}
	return sum;
}
double ans;int pos;
void work(int u)
{
	int rt=0;all_nd.clear();dfs_bas(u,0);
	for(int i=0;i<all_nd.size();i++)if(rt==0||max(sz[u]-sz[all_nd[i]],maxsz[all_nd[i]])<=(sz[u]>>1))rt=all_nd[i];
	if(!rt)return;dis[rt]=0;double sum=dfs_calc(rt,0);
	if(ans>sum){ans=sum,pos=rt;}
	ban[rt]=1;double sumd=der[rt];
	//printf("%d %d\n",u,rt);
	for(int i=0;i<ed[rt].size();i++)
	{
		int v=ed[rt][i].to;if(!ban[v]&&sumd-2*der[v]<0){work(v);break;}
	}
}

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lf",&w[i]);
	for(int i=1,x=0,y=0;i<n;i++)
	{
		double v=0;scanf("%d%d%lf",&x,&y,&v);ed[x].push_back(e(y,v)),ed[y].push_back(e(x,v));
	}
	ans=1e20;work(1);printf("%d %.10lf",pos,ans);return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,w[N],ht=0,hd[N],ans1;
struct edge{int v,w,n;}e[N*2];
void addedge(int u,int v,int w){
    e[++ht]=(edge){v,w,hd[u]};
    hd[u]=ht;
}
double ans2=1e18,sum,d[N],sd;
int s[N],rt,rts=N,vis[N];
void getrt(int u,int F,int S){
    s[u]=1;int us=0;
    for(int i=hd[u],v;i;i=e[i].n){
        v=e[i].v;if(vis[v]||v==F)continue;
        getrt(v,u,S),s[u]+=s[v];
        us=max(us,s[v]);
    }
    us=max(us,S-s[u]);
    if(us<rts) rt=u,rts=us;
}
void calc(int u,int F,int z){
    sum+=pow(z,1.5)*w[u];
    d[u]=pow(z,0.5)*1.5*w[u];
    for(int i=hd[u],v;i;i=e[i].n){
        v=e[i].v;if(v==F)continue;
        calc(v,u,z+e[i].w),d[u]+=d[v];
    }
}
void work(int x,int S){
    getrt(x,0,S);
    getrt(x=rt,0,S);
    vis[x]=1,sum=sd=0;
    for(int i=hd[x];i;i=e[i].n){
        calc(e[i].v,x,e[i].w);
        sd+=d[e[i].v];
    }
    if(sum<ans2) ans1=x,ans2=sum;
    for(int i=hd[x];i;i=e[i].n){
        if(vis[e[i].v]) continue;
        if(sd-d[e[i].v]*2>=0) continue;
        work(e[i].v,s[e[i].v]); break;
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1,u,v,w;i<n;i++){
        scanf("%d%d%d",&u,&v,&w);
        addedge(u,v,w),addedge(v,u,w);
    }
    work(1,n);
    printf("%d %.10lf\n",ans1,ans2);
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
double sum[200005],b[200005],ans,inf=1e20,maxx;
int a[200005],n,rt,siz[200005],son[200005],h[200005],vis1[200005],cnt,sit;
struct l1{
	int to,next,v;
}p[400005];
void add(int x,int y,int v){
	cnt++;
	p[cnt].to=y;
	p[cnt].next=h[x];
	h[x]=cnt;
	p[cnt].v=v;
}
void dfs1(int x,int fa,int num){
	siz[x]=1;son[x]=0;
	for(int i=h[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa||vis1[y]) continue;
		dfs1(y,x,num);
		if(siz[y]>siz[son[x]]) son[x]=y;
		siz[x]+=siz[y];
	}
	if(max(siz[son[x]],num-siz[x])<maxx){
		maxx=max(siz[son[x]],num-siz[x]);
		rt=x;
	}
}
void dfs2(int x,int fa,int fro){
	sum[x]=pow(fro,1.5)*a[x],b[x]=pow(fro,0.5)*1.5*a[x];
	for(int i=h[x];i;i=p[i].next){
		int y=p[i].to;
		if(y==fa) continue;
		dfs2(y,x,fro+p[i].v);
		sum[x]+=sum[y];b[x]+=b[y];
	}
}
void dfz(int x,int num){
	maxx=inf;rt=x;
	dfs1(x,0,num);
	int now_rt=rt;
	vis1[now_rt]=1;
	dfs2(now_rt,0,0);
	if(ans>sum[now_rt]) ans=min(ans,sum[now_rt]),sit=now_rt;
	for(int i=h[now_rt];i;i=p[i].next){
		int y=p[i].to;
		if(vis1[y]) continue;
		if(b[now_rt]-2*b[y]>=0) continue;
		dfz(y,siz[y]);
		break;
	}
}
int main(){
	ans=inf;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;i++){
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		add(x,y,v);add(y,x,v);
	}
	dfz(1,n);
	printf("%d %.10f",sit,ans);
}


#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define X first
#define Y second
using namespace std;
const int N = 2e5+10;
bool used[N];
int visit[N];
int w[N];
int V;
int t_size[N];
int n;
vector< pair<int ,int>> Edge[N];
int total_size;
int c_dfs(int x, int& c){
 visit[x] = V;
 int m_ch = 0;
 t_size[x] = 1;
 for(auto nx: Edge[x]){
    int next = nx.X;
    if(!used[next] && visit[next]!=V){
      int ch_size = c_dfs(next,c);
      m_ch = max(m_ch, ch_size);
      t_size[x] += ch_size;
    }
  }
  m_ch = max(m_ch, total_size - t_size[x]);
  if(total_size/2 >= m_ch) c = x;
  return t_size[x];
}
double d3[N];
double d1[N];
void dfs(int x, int level){
  visit[x] = V;
  d3[x] = sqrt(level)*level*w[x];
  d1[x] = sqrt(level) *w[x];
  for(auto nx: Edge[x]){
    int next = nx.X;
    if(visit[next]==V)continue;
    dfs(next, level+nx.Y);
    d3[x] += d3[next];
    d1[x] += d1[next];
  }
}
int ans_node;
double solve(){
  int st = 1;
  int c;
  total_size = n;
  double res = 1e100;
  while(!used[st]){
    V++;
    c_dfs(st,c);
    used[c] = true;
    V++;
    dfs(c,0);
    if(d3[c] < res){
      res = d3[c];
      ans_node = c;
    }
    bool flag  = true;
    for(auto nx:Edge[c]){
      int next = nx.X;
      if(used[next])continue;
      if(d1[c] - 2*d1[next] < 0){
        flag = false;
        total_size = (t_size[c]>t_size[next])?t_size[next]:total_size-t_size[c];
        st = next;
        break;
      }
    }
    if(flag)break;
  }
  return res;
}
int main(){
  scanf("%d",&n);
  FOR1(i,n)scanf("%d",&w[i]);
  FOR1(i,n-1){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    Edge[a].push_back(make_pair(b,c)) ;
    Edge[b].push_back(make_pair(a,c)) ;
  }
  double ans = solve();
  printf("%d %.10lf\n",ans_node,ans);
}

// ntuj - 5rxtu1k7pveihe7nhty2o


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
const int MX = 200005;

int N, ip[MX];
vector<pii> E[MX];
int fr, bk, que[MX], vst[MX], fa[MX], sz[MX], ok[MX], val[MX];
LL dis[MX];
double ans = 1e20;

bool BFS(int st) {
    fr = bk = 0;
    que[bk++] = st;
    vst[st] = 1;
    fa[st] = st;
    dis[st] = 0;
    while (fr < bk) {
        int u = que[fr++];
        for (auto it : E[u]) {
        	int v = it.first, w = it.second;
            if (!ok[v] || vst[v]) continue;
            que[bk++] = v;
            vst[v] = 1;
            dis[v] = dis[u] + w;
            fa[v] = u;
        }
    }
    for (int i=0; i<bk; i++) {
        vst[que[i]] = 0;
    }
}
int findCentroid(int st) {
    int ret = -1, cost = 1029384756;
    BFS(st);
    for (int i=bk-1; i>=0; i--) {
        int u = que[i], mx = 0;
        sz[u] = 1;
        for (auto it : E[u]) {
        	int v = it.first;
            if (!ok[v] || v == fa[u]) continue;
            sz[u] += sz[v];
            mx = max(mx, sz[v]);
        }
        mx = max(mx, bk-sz[u]);
        if (mx < cost) {
            cost = mx;
            ret = u;
        }
    }
    return ret;
}
double calcAnswer(int st) {
	double ret = 0;
	memset(dis, -1, sizeof(dis));
	fr = bk = 0;
	que[bk++] = st;
	dis[st] = 0;
	fa[st] = st;
	while (fr < bk) {
		int u = que[fr++];
		ret += dis[u] * sqrt(dis[u]) * ip[u];
		for (auto it : E[u]) {
			int v = it.first, w = it.second;
			if (dis[v] != -1) continue;
			fa[v] = u;
			dis[v] = dis[u] + w;
			que[bk++] = v;
		}
	}
	for (int i=bk-1; i>=0; i--) {
		int u = que[i];
		double tmp = 0;
		for (auto it : E[u]) {
			int v = it.first;
			if (v == fa[u]) continue;
			tmp += val[v];
			tmp += sqrt(dis[v]) * ip[v];
		}
		val[u] = tmp;
	}
	return ret;
}

void go(int st) {
	int cent = findCentroid(st);
	ok[cent] = 0;
	ans = min(ans, calcAnswer(cent));
	int nxt = -1;
	for (auto it : E[cent]) {
		int v = it.first;
		if (!ok[v]) continue;
		if (nxt == -1 || val[v] > val[nxt]) {
			nxt = v;
		}
	}
	if (nxt != -1) {
		go(nxt);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> N;
	for (int i=1; i<=N; i++) {
		cin >> ip[i];
	}
	for (int i=2, u, v, w; i<=N; i++) {
		cin >> u >> v >> w;
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	for (int i=1; i<=N; i++) {
		ok[i] = 1;
	}
	go(1);
	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}
// ntuj - mq08wewn1fu1zqdi523ge


#include<stdio.h>
#include<vector>
#include<string.h>
#include<math.h>
#define MAX 200010
#define INF 1e18
#define eps 1e-10
double w[MAX];
struct ele{
	int x;
	double d;
};
std::vector<ele>edge[MAX];
std::vector<int>tmp;
int dp[MAX],tot[MAX];
bool use[MAX],vi[MAX];
double der[MAX],di[MAX];
int n;
void ini(){
	for(int k=0;k<tmp.size();k++){
		int i=tmp[k];
		tot[i]=-1;
		dp[i]=0;
	}
	tmp.clear();
	return;
}
void cent(int x){
	tot[x]=1;
	tmp.push_back(x);
	for(int k=0;k<edge[x].size();k++){
		int i=edge[x][k].x;
		if(use[i]) continue;
		if(tot[i]==-1){
			cent(i);
		}
		else continue;
		dp[x]=std::max(dp[x],tot[i]);
		tot[x]+=tot[i];
	}
	return;
}
void dfs(int x,int y){
	vi[x]=true;
	for(int k=0;k<edge[x].size();k++){
		int i=edge[x][k].x;
		if(vi[i]) continue;
		di[i]=di[x]+edge[x][k].d;
		der[y]+=sqrt(di[i])*w[i];
		dfs(i,y);
	}
	return;
}
void dfs2(int x,int y){
	vi[x]=true;
	for(int k=0;k<edge[x].size();k++){
		int i=edge[x][k].x;
		if(vi[i]) continue;
		di[i]=di[x]+edge[x][k].d;
		der[y]+=di[i]*sqrt(di[i])*w[i];
		dfs2(i,y);
	}
	return;
}
void print(){
	double min=1e30;
	int ans;
	for(int k=0;k<tmp.size();k++){
		int i=tmp[k];
		memset(vi,false,sizeof(vi));
		di[i]=0;der[k]=0;
		dfs2(i,k);
		if(der[k]<min){
			min=der[k];
			ans=i;
		}
	}
	printf("%d %.10f",ans,min);
	return;
}
void tru(int x){
	ini();
	int min=1e9,it;
	double sum=0;
	cent(x);
	for(int k=0;k<tmp.size();k++){
		int i=tmp[k];
		if(min>std::max(dp[i],tot[x]-tot[i])){
			min=std::max(dp[i],tot[x]-tot[i]);
			it=i;
		}
	}
	use[it]=true;
	memset(vi,false,sizeof(vi));
	vi[it]=true;
	for(int k=0;k<edge[it].size();k++){
		int i=edge[it][k].x;
		der[k]=0;di[i]=edge[it][k].d;
		der[k]+=sqrt(di[i])*w[i];
		dfs(i,k);
		sum+=der[k];
	}
	int in=-1;
	for(int k=0;k<edge[it].size();k++){
		if(sum-2*der[k]<eps){
			in=k;
			break;
		}
	}
	if(in==-1){
		tmp.clear();
		tmp.push_back(it);
		print();
		return;
	}
	if(use[edge[it][in].x]){
		tmp.push_back(edge[it][in].x);
		print();
		return;
	}
	tru(edge[it][in].x);
	return;
}
int main(){
	int a,b,k;
	double d;
	scanf("%d",&n);
	for(k=1;k<=n;k++){
		scanf("%lf",&w[k]);
	}
	for(k=1;k<n;k++){
		scanf("%d%d%lf",&a,&b,&d);
		edge[a].push_back(ele{b,d});
		edge[b].push_back(ele{a,d});
	}
	memset(tot,-1,sizeof(tot));
	tru(1);
}
// ntuj - 7e9jai2njfltiwlwesnt9


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN=200010;

int N,w[MAXN];
vector<PII> e[MAXN];
bool vis[MAXN];
int cnt[MAXN],big[MAXN];

double ans=1e25;
int ansdot;

VI group;
void DFS1(int x,int p) {
    group.PB(x);
    cnt[x]=1;
    big[x]=0;
    for(PII u:e[x]) {
        if(u.F==p || vis[u.F])
            continue;
        DFS1(u.F,x);
        cnt[x]+=cnt[u.F];
        big[x]=max(big[x],cnt[u.F]);
    }
}

double subtree;

double DFS2(int x,int p,int d) {
    subtree+=sqrt(d)*w[x];
    double re=(double)sqrt(d)*d*w[x];
    for(PII u:e[x]) {
        if(u.F==p)
            continue;
        re+=DFS2(u.F,x,d+u.S);
    }
    return re;
}

int main() {
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",w+i);
    int a,b,l;
    for(int i=1;i<N;i++) {
        scanf("%d%d%d",&a,&b,&l);
        e[a].PB(MP(b,l));
        e[b].PB(MP(a,l));
    }
    int tar=1;
    while(1) {
        group.clear();
        DFS1(tar,0);
        int h=-1,hmax=MAXN,sum=cnt[tar];
        for(int t:group) {
            big[t]=max(big[t],sum-cnt[t]);
            if(big[t]<hmax)
                h=t, hmax=big[t];
        }
        vis[h]=1;
        int to=-1;
        double tomax=-1.0,tmp=0.0;
        for(PII u:e[h]) {
            subtree=0.0;
            tmp+=DFS2(u.F,h,u.S);
            if(subtree>tomax)
                to=u.F, tomax=subtree;
        }
        if(tmp<ans)
            ansdot=h, ans=tmp;
        tar=to;
        if(vis[tar])
            break;
    }
    printf("%d %.10f\n",ansdot,ans);
    return 0;
}

// ntuj - m4t3qnyqsm1sycn7gvd8t


#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
int w[200000];
std::vector<std::pair<int, int>> adj[200000];
bool vis[200000];
int get_size(int x, int p = -1) {
    int size = 1;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p && !vis[c])
            size += get_size(c, x);
    }
    return size;
}
int dfs1(int x, int fullsz, int p = -1) {
    int size = 1;
    bool ok = true;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p && !vis[c]) {
            int csize = dfs1(c, fullsz, x);
            if(csize <= 0)
                return csize;
            if(csize > fullsz / 2)
                ok = false;
            size += csize;
        }
    }
    if(ok && (fullsz - size) <= fullsz / 2)
        return -x;
    return size;
}
int get_centroid(int x, int fullsz) {
    return -dfs1(x, fullsz, -1);
}
double dfs2(int x, int l, int p = -1) {
    double sum = w[x] * std::sqrt(l) * 1.5;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p) {
            int lc = pi.second;
            sum += dfs2(c, l + lc, x);
        }
    }
    return sum;
}
int get_gradient(int x) {
    double sum = 0;
    for(auto pi : adj[x]) {
        int c = pi.first;
        int l = pi.second;
        sum += dfs2(c, l);
    }
    for(auto pi : adj[x]) {
        int c = pi.first;
        int l = pi.second;
        if(dfs2(c, l) * 2 >= sum)
            return c;
    }
    return -1;
}
double get_cost(int x, int l = 0, int p = -1) {
    double sum = w[x] * std::sqrt(l) * l;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p) {
            int lc = pi.second;
            sum += get_cost(c, l + lc, x);
        }
    }
    return sum;
}
int main() {
    int n;
    std::scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", w + i);
    for(int i = 0; i < n - 1; i++) {
        int u, v, l;
        scanf("%d %d %d", &u, &v, &l);
        u--, v--;
        adj[u].emplace_back(v, l);
        adj[v].emplace_back(u, l);
    }
    int region = 0;
    while(true) {
        int size = get_size(region);
        int cent = get_centroid(region, size);
        int grad = get_gradient(cent);
        // printf("> %d %d %d\n", size, cent, grad);
        if(grad == -1 || vis[grad]) {
            printf("%d %.18f\n", cent + 1, get_cost(cent));
            break;
        } else {
            vis[cent] = true;
            region = grad;
        }
    }
}

// ntuj - 8n24medhwgkbufii2tgrv


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
int n;
int w[200005];
vector< pair<int,int> > v[200005];
int centroid;
int ch[200005],vis[200005];
double grd[200005];
double ans[200005];
void dfs(int now,int pre,int sz){
	int i;
	ch[now]=1;
	int maxch=0;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(vis[to]||to==pre) continue;
		dfs(to,now,sz);
		maxch=max(maxch,ch[to]);
		ch[now]+=ch[to];
		ch[to]=0;
	}
	maxch=max(maxch,sz-ch[now]);
	if(maxch<=sz/2)
	  centroid=now;
}
int dfs2(int now,int pre){
	int ret=1;
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(vis[to]||to==pre) continue;
		ret+=dfs2(to,now);
	}
	return ret;
}
void gradi(int now,int pre,long long int len){
	grd[now]=sqrt(len)*w[now];
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(to==pre) continue;
		gradi(to,now,len+v[now][i].S);
		grd[now]+=grd[to];
	}
}
double getans(int now,int pre,long long int len){
	double ret=sqrt(len)*len*w[now];
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(to==pre) continue;
		ret+=getans(to,now,len+v[now][i].S);
	}
	return ret;
}
void entry(int pt,int sz){
	int cent;
	int i;
	dfs(pt,pt,sz);
	ch[pt]=0;
	cent=centroid;
	vis[cent]=1;
	gradi(cent,cent,0);
	ans[cent]=getans(cent,cent,0);
	double totgrd=0;
	for(i=0;i<v[cent].size();i++){
		totgrd+=grd[v[cent][i].F];
	}
	for(i=0;i<v[cent].size();i++){
		int ch=v[cent][i].F;
	//	printf(" # %d %d %f\n",cent,ch,totgrd-2*grd[ch]);
		if(totgrd-2*grd[ch]<0){
			if(vis[ch]) continue;
			else{
				int chsz=dfs2(ch,ch);
				entry(ch,chsz);
			}
		}
	}
}
int main(void){
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++){
		scanf("%d",&w[i]);
		ch[i]=0;
		vis[i]=0;
		ans[i]=-1;
	}
	for(i=0;i<n-1;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		v[a].PB(MP(b,c));
		v[b].PB(MP(a,c));
	}
	entry(1,n);
	int Ans=0;
	for(i=2;i<=n;i++){
		if(ans[i]==-1)continue;
		if(!Ans) Ans=i;
		if(ans[i]<ans[Ans]) Ans=i;
	}
	printf("%d %.8f\n",Ans,ans[Ans]);
	return 0;
}

// ntuj - n5yg6gjwlvwaqwhb4ep7b


#include<bits/stdc++.h>
using namespace std;
#define FZ(i,n) for(int i=0;i<(n);i++)
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()

#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d %d",&(x),&(y))
#define PA(a,n) FZ(_1,n)printf("%d%c",(a)[_1],_1==(n)-1?10:32)
#define ePA(a,n) FZ(_2,n)fprintf(stderr,"%d%c",(a)[_2],_2==(n)-1?10:32)

#define RS(x) scanf("%s",x)
#define PS(x) printf("%s",x)
#define ePS(x) fprintf(stderr,"%s",x)

#define RI64(x) scanf("%I64d",&(x))
#define RII64(x,y) scanf("%I64d%I64d",&(x),&(y))
#define PA64(a,n) FZ(_1,n)printf("%I64d%c",(a)[_1],_1==(n)-1?10:32)
#define ePA64(a,n) FZ(_2,n)fprintf(stderr,"%I64d%c",(a)[_2],_2==(n)-1?10:32)

#define FIR first
#define SEC second
#define pritnf printf
#define N 200514
typedef long long int lnt;
typedef double dou;
typedef pair<int,int> P;
typedef struct{int t;dou w;}edge;
vector<edge>e[N];
int n;
dou W[N];
//////////////
int vis[N];
int sum[N],mxs[N],stk[N],top;
void dfs0(int w){
	vis[w]=1;
	sum[w]=1;
	mxs[w]=0;
	stk[top++]=w;
	for(auto it:e[w]){
		int t=it.t;
		if(vis[t])continue;
		dfs0(t);
		sum[w]+=sum[t];
		mxs[w]=max(mxs[w],sum[t]);
	}
}
//////////////
dou dis[N],wei[N],dfstmp,anstmp;
void dfs1(int w,int f,dou nd){
	dis[w]=nd;
	wei[w]=sqrt(nd);
	dfstmp+=wei[w]*W[w];
	anstmp+=dis[w]*wei[w]*W[w];
	for(auto it:e[w]){
		int t=it.t;
		if(t==f)continue;
		dfs1(t,w,nd+it.w);
	}
}
int q[N],qs,qe;
int sol(int uuu){
	FZ(i,n)scanf("%lf",W+i);
	FZ(i,n)e[i].clear();
	FZ(i,n-1){
		int x,y;dou z;
		RII(x,y);scanf("%lf",&z);x--,y--;
		e[x].push_back((edge){y,z});
		e[y].push_back((edge){x,z});
	}
	/////////////////////////////
	dou ans=1e30;int aaa=-1;
	FZ(i,n)vis[i]=0;
	qs=qe=0;
	q[qe++]=0;
	for(;qs!=qe;){
		int w=q[qs++];
		top=0;
		dfs0(w);
		int g=w;
		int gs=top;
		FZ(i,top){
			int j=stk[i];
			mxs[j]=max(mxs[j],top-sum[j]);
			if(gs>mxs[j]){
				gs=mxs[j];
				g=j;
			}
		}
		//printf("g=%d\n",g);
		////////////////////
		dou tmp=0,sss=0;int nt=-1;
		anstmp=0;
		for(auto it:e[g]){
			int t=it.t;
			dfstmp=0;
			dfs1(t,g,it.w);
			sss+=dfstmp;
			if(tmp<dfstmp){
				tmp=dfstmp;
				nt=t;
			}
		}
		//printf("wei=%f\n",sss-2*tmp);
		if(ans>anstmp){
			ans=anstmp;
			aaa=g;
		}
		if(nt==-1||vis[nt]==2)break;
		////////////////////
		FZ(i,top)vis[stk[i]]=0;
		vis[g]=2;
		q[qe++]=nt;
	}
	assert(aaa!=-1);
	printf("%d %.10f\n",aaa+1,ans);
	return 1;
}
int main(){
	while(RI(n)!=EOF)sol(0);
	return 0;
}

// ntuj - f9jqswfmwhilt7vxsomyz


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pid;
const int maxn = 200000 + 10;
#define repe(i, a, b) for(int i = a; i <= b; ++i)
int n;
vector<pid> g[maxn];
int w[maxn];
int ans;
double ansv;
bool rm[maxn] = {};

double dist[maxn], grad[maxn];

void dfs2(int root, int x, int p, double d) {
	dist[root] += d * sqrt(d) * w[x];
	grad[root] += sqrt(d) * w[x];
	for(pid t: g[x]) {
		int y = t.first;
		if(y != p) dfs2(root, y, x, d + t.second);
	}
}

int go(int x) {
	double sum = 0;
	double gg = -1;
	int ch = -1;
	for(pid t: g[x]) {
		int y = t.first;
		dist[y] = grad[y] = 0;
		dfs2(y, y, x, t.second);
		sum += dist[y];
		if(grad[y] > gg) {
			gg = grad[y];
			ch = y;
		}
	}
	if(sum < ansv) {
		ansv = sum;
		ans = x;
	}
	return ch;
}
int sz[maxn];
int dfs(int x, int p) {
	sz[x] = 1;
	for(pid t: g[x]) {
		int y = t.first;
		if(y != p && !rm[y]) sz[x] += dfs(y, x);
	}
	return sz[x];
}
int center(int x) {
	dfs(x, -1);
	int p = -1;
	int cap = sz[x] >> 1;
	for(;;) {
		bool fg = false;
		for(pid t: g[x]) {
			int y = t.first;
			if(!rm[y] && y != p && sz[y] > cap) {
				fg = true;
				p = x;
				x = y;
				break;
			}
		}
		if(!fg) return x;
	}
}
void solve(int x) {
	for(;x && !rm[x];) {
		int y = center(x);
		x = go(y);
		rm[y] = true;
	}
}

int main() {
	scanf("%d", &n);
	repe(i, 1, n) scanf("%d", &w[i]);
	repe(i, 2, n) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	ansv = 1e22;
	solve(1);
	printf("%d %.12f\n", ans, ansv);
	return 0;
}

// ntuj - k76qcdm5r4icv2bymxqqr


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 2e5+10;
// template end here
VPII e[SIZE],emp;
int N,L,R;
int NUM[SIZE];
int d[SIZE],dn;
int bfs[SIZE],sons[SIZE];
int used[SIZE],tt,tt2,father[SIZE];
vector<int>qq;
template <class T>
void maa(T& x,T y){
    if(x<y)x=y;
}
template <class T>
void mii(T& x,T y){
    if(x>y)x=y;
}
void build(int st){
    bfs[0]=st;
    tt2--;
    used[st]=tt2;
    int i=0,j=1;
    for(;i<j;i++){
        int x=bfs[i];
        sons[x]=1;
        REP(k,SZ(e[x])){
            int y=e[x][k].F;
            if(used[y]==tt||used[y]==tt2)continue;
            father[y]=x;
            used[y]=tt2;
            bfs[j++]=y;
        }
    }
    int num=j;
    for(i=j-1;i>=0;i--){
        int x=bfs[i];
        if(sons[x]*2>=num){
            qq.PB(x);
            used[x]=tt;
            REP(k,SZ(e[x])){
                int y=e[x][k].F;
                if(used[y]!=tt)build(y);
            }
            return;
        }
        sons[father[x]]+=sons[x];
    }
}
void init(){
    tt++;
    qq.clear();
    build(0);
}
int ans_id;
double ans_v;
double tmp_v;
void dfs9(int x,int v,int lt){
    tmp_v+=pow(v,1.5)*NUM[x];
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        if(y==lt)continue;
        dfs9(y,v+e[x][i].S,x);
    }
}
void fresh(int x){
    tmp_v=0;
    dfs9(x,0,x);
    if(tmp_v<ans_v){
        ans_id=x;
        ans_v=tmp_v;
    }
}
double delta[SIZE];
int from;
void dfs5(int x,int lt,int v){
    delta[from]+=sqrt(v)*NUM[x];
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        if(y==lt)continue;
        dfs5(y,x,v+e[x][i].S);
    }
}
void dfs3(int x,int lt){
    if(used[x]==tt)return;
    used[x]=tt;
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        if(y!=lt)dfs3(y,x);
    }
}
bool Go(){
    tt++;
    REP(i,SZ(qq)){
        int me=qq[i];
        if(used[me]==tt)continue;
        fresh(me);
        used[me]=tt;
        double sum=0;
        REP(i,SZ(e[me])){
            from=e[me][i].F;
            delta[from]=0;
            dfs5(from,me,e[me][i].S);
            sum+=delta[from];
        }
        REP(i,SZ(e[me])){
            int y=e[me][i].F;
            if(delta[y]*2-sum<1e-12){
                dfs3(y,me);
            }
        }
    }
    return 0;
}
int main(){
    RI(N);
    dn=0;
    REP(i,N)e[i]=emp;
    REP(i,N)RI(NUM[i]);
    REPP(i,1,N){
        DRIII(x,y,v);
        x--;y--;
        e[x].PB(MP(y,v));
        e[y].PB(MP(x,v));
    }
    init();
    ans_v=1e100;
    Go();
    printf("%d %.9f\n",ans_id+1,ans_v);
    return 0;
}

// ntuj - nfqmjz3w40kxrb0gqi3ws


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
const int MX = 200005;

int N, ip[MX];
vector<pii> E[MX];
int fr, bk, que[MX], vst[MX], fa[MX], sz[MX], ok[MX], val[MX];
LL dis[MX];
int bestid = -1;
double ans = 1e20;

bool BFS(int st) {
    fr = bk = 0;
    que[bk++] = st;
    vst[st] = 1;
    fa[st] = st;
    dis[st] = 0;
    while (fr < bk) {
        int u = que[fr++];
        for (auto it : E[u]) {
        	int v = it.first, w = it.second;
            if (!ok[v] || vst[v]) continue;
            que[bk++] = v;
            vst[v] = 1;
            dis[v] = dis[u] + w;
            fa[v] = u;
        }
    }
    for (int i=0; i<bk; i++) {
        vst[que[i]] = 0;
    }
}
int findCentroid(int st) {
    int ret = -1, cost = 1029384756;
    BFS(st);
    for (int i=bk-1; i>=0; i--) {
        int u = que[i], mx = 0;
        sz[u] = 1;
        for (auto it : E[u]) {
        	int v = it.first;
            if (!ok[v] || v == fa[u]) continue;
            sz[u] += sz[v];
            mx = max(mx, sz[v]);
        }
        mx = max(mx, bk-sz[u]);
        if (mx < cost) {
            cost = mx;
            ret = u;
        }
    }
    return ret;
}
double calcAnswer(int st) {
	double ret = 0;
	memset(dis, -1, sizeof(dis));
	fr = bk = 0;
	que[bk++] = st;
	dis[st] = 0;
	fa[st] = st;
	while (fr < bk) {
		int u = que[fr++];
		ret += dis[u] * sqrt(dis[u]) * ip[u];
		for (auto it : E[u]) {
			int v = it.first, w = it.second;
			if (dis[v] != -1) continue;
			fa[v] = u;
			dis[v] = dis[u] + w;
			que[bk++] = v;
		}
	}
	for (int i=bk-1; i>=0; i--) {
		int u = que[i];
		double tmp = sqrt(dis[u]) * ip[u];
		for (auto it : E[u]) {
			int v = it.first;
			if (v == fa[u]) continue;
			tmp += val[v];
		}
		val[u] = tmp;
	}
	return ret;
}

void go(int st) {
	int cent = findCentroid(st);
	ok[cent] = 0;
	double tmp = calcAnswer(cent);
	if (ans > tmp) {
		ans = tmp;
		bestid = cent;
	}
	int nxt = -1;
	for (auto it : E[cent]) {
		int v = it.first;
		if (!ok[v]) continue;
		if (nxt == -1 || val[v] > val[nxt]) {
			nxt = v;
		}
	}
	if (nxt != -1) {
		go(nxt);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> N;
	for (int i=1; i<=N; i++) {
		cin >> ip[i];
	}
	for (int i=2, u, v, w; i<=N; i++) {
		cin >> u >> v >> w;
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	for (int i=1; i<=N; i++) {
		ok[i] = 1;
	}
	go(1);
	cout << bestid << " " << fixed << setprecision(10) << ans << endl;

	return 0;
}
// ntuj - ja6cec8qhb69st4n93s4l


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pid;
const int maxn = 200000 + 10;
#define repe(i, a, b) for(int i = a; i <= b; ++i)
int n;
vector<pid> g[maxn];
int w[maxn];
int ans;
double ansv;
bool rm[maxn] = {};

double dist[maxn], grad[maxn];

void dfs2(int root, int x, int p, double d) {
	dist[root] += d * sqrt(d) * w[x];
	grad[root] += sqrt(d) * w[x];
	for(pid t: g[x]) {
		int y = t.first;
		if(y != p) dfs2(root, y, x, d + t.second);
	}
}

int go(int x) {
	double sum = 0;
	double gg = -1;
	int ch = -1;
	for(pid t: g[x]) {
		int y = t.first;
		dist[y] = grad[y] = 0;
		dfs2(y, y, x, t.second);
		sum += dist[y];
		if(grad[y] > gg) {
			gg = grad[y];
			ch = y;
		}
	}
	if(sum < ansv) {
		ansv = sum;
		ans = x;
	}
	return ch;
}
int sz[maxn];
int dfs(int x, int p) {
	sz[x] = 1;
	for(pid t: g[x]) {
		int y = t.first;
		if(y != p && !rm[y]) sz[x] += dfs(y, x);
	}
	return sz[x];
}
int center(int x) {
	dfs(x, -1);
	int p = -1;
	int cap = sz[x] >> 1;
	for(;;) {
		bool fg = false;
		for(pid t: g[x]) {
			int y = t.first;
			if(!rm[y] && y != p && sz[y] > cap) {
				fg = true;
				p = x;
				x = y;
				break;
			}
		}
		if(!fg) return x;
	}
}
void solve(int x) {
	for(;x && !rm[x];) {
		int y = center(x);
		x = go(y);
		rm[y] = true;
	}
}

int main() {
	scanf("%d", &n);
	repe(i, 1, n) scanf("%d", &w[i]);
	repe(i, 2, n) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	ansv = 1e22;
	solve(1);
	printf("%d %.12f\n", ans, ansv);
	return 0;
}

// ntuj - kxij3u6803ba4z3dv59lq


#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
int w[200000];
std::vector<std::pair<int, int>> adj[200000];
bool vis[200000];
int get_size(int x, int p = -1) {
    int size = 1;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p && !vis[c])
            size += get_size(c, x);
    }
    return size;
}
int dfs1(int x, int fullsz, int p = -1) {
    int size = 1;
    bool ok = true;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p && !vis[c]) {
            int csize = dfs1(c, fullsz, x);
            if(csize <= 0)
                return csize;
            if(csize > fullsz / 2)
                ok = false;
            size += csize;
        }
    }
    if(ok && (fullsz - size) <= fullsz / 2)
        return -x;
    return size;
}
int get_centroid(int x, int fullsz) {
    return -dfs1(x, fullsz, -1);
}
double dfs2(int x, int l, int p) {
    double sum = w[x] * std::sqrt(l) * 1.5;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p) {
            int lc = pi.second;
            sum += dfs2(c, l + lc, x);
        }
    }
    return sum;
}
double get_cost(int x, int l = 0, int p = -1) {
    double sum = w[x] * std::sqrt(l) * l;
    for(auto pi : adj[x]) {
        int c = pi.first;
        if(c != p) {
            int lc = pi.second;
            sum += get_cost(c, l + lc, x);
        }
    }
    return sum;
}
int get_gradient(int x) {
    double sum = 0, max = 0;
    int who = adj[x][0].first;
    for(auto pi : adj[x]) {
        int c = pi.first;
        int l = pi.second;
        double g = dfs2(c, l, x);
        sum += g;
        if(g > max) {
            max = g;
            who = c;
        }
    }
    if(max * 2 >= sum && get_cost(x) >= get_cost(who))
        return who;
    return -1;
}
int main() {
    int n;
    std::scanf("%d", &n);
    for(int i = 0; i < n; i++)
        std::scanf("%d", w + i);
    if(n == 1)
        std::puts("1 0");
    for(int i = 0; i < n - 1; i++) {
        int u, v, l;
        std::scanf("%d %d %d", &u, &v, &l);
        u--, v--;
        adj[u].emplace_back(v, l);
        adj[v].emplace_back(u, l);
    }
    int region = 0;
    while(true) {
        int size = get_size(region);
        int cent = get_centroid(region, size);
        int grad = get_gradient(cent);
        // std::printf("> %d %d %d\n", size, cent, grad);
        if(grad == -1 || vis[grad]) {
            std::printf("%d %.18f\n", cent + 1, get_cost(cent));
            break;
        } else {
            vis[cent] = true;
            region = grad;
        }
    }
}

// ntuj - 8ngbkvqhscqby42h5m8y5


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
const int MX = 200005;

int N, ip[MX];
vector<pii> E[MX];
int fr, bk, que[MX], vst[MX], fa[MX], sz[MX], ok[MX];
LL dis[MX];
int bestid = -1;
double ans = 1e20, val[MX];

bool BFS(int st) {
    fr = bk = 0;
    que[bk++] = st;
    vst[st] = 1;
    fa[st] = st;
    dis[st] = 0;
    while (fr < bk) {
        int u = que[fr++];
        for (auto it : E[u]) {
        	int v = it.first, w = it.second;
            if (!ok[v] || vst[v]) continue;
            que[bk++] = v;
            vst[v] = 1;
            dis[v] = dis[u] + w;
            fa[v] = u;
        }
    }
    for (int i=0; i<bk; i++) {
        vst[que[i]] = 0;
    }
}
int findCentroid(int st) {
    int ret = -1, cost = 1029384756;
    BFS(st);
    for (int i=bk-1; i>=0; i--) {
        int u = que[i], mx = 0;
        sz[u] = 1;
        for (auto it : E[u]) {
        	int v = it.first;
            if (!ok[v] || v == fa[u]) continue;
            sz[u] += sz[v];
            mx = max(mx, sz[v]);
        }
        mx = max(mx, bk-sz[u]);
        if (mx < cost) {
            cost = mx;
            ret = u;
        }
    }
    return ret;
}
double calcAnswer(int st) {
	double ret = 0;
	memset(dis, -1, sizeof(dis));
	fr = bk = 0;
	que[bk++] = st;
	dis[st] = 0;
	fa[st] = st;
	while (fr < bk) {
		int u = que[fr++];
		ret += dis[u] * sqrt(dis[u]) * ip[u];
		for (auto it : E[u]) {
			int v = it.first, w = it.second;
			if (dis[v] != -1) continue;
			fa[v] = u;
			dis[v] = dis[u] + w;
			que[bk++] = v;
		}
	}
	for (int i=bk-1; i>=0; i--) {
		int u = que[i];
		double tmp = sqrt(dis[u]) * ip[u];
		for (auto it : E[u]) {
			int v = it.first;
			if (v == fa[u]) continue;
			tmp += val[v];
		}
		val[u] = tmp;
	}
	return ret;
}

void go(int st) {
	int cent = findCentroid(st);
	ok[cent] = 0;
	double tmp = calcAnswer(cent);
	if (ans > tmp) {
		ans = tmp;
		bestid = cent;
	}
	int nxt = -1;
	for (auto it : E[cent]) {
		int v = it.first;
		if (!ok[v]) continue;
		if (nxt == -1 || val[v] > val[nxt]) {
			nxt = v;
		}
	}
	if (nxt != -1) {
		go(nxt);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> N;
	for (int i=1; i<=N; i++) {
		cin >> ip[i];
	}
	for (int i=2, u, v, w; i<=N; i++) {
		cin >> u >> v >> w;
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	for (int i=1; i<=N; i++) {
		ok[i] = 1;
	}
	go(1);
	cout << bestid << " " << fixed << setprecision(10) << ans << endl;

	return 0;
}
// ntuj - 4q8a0934p89wdaanatc6d


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
int n;
int w[200005];
vector< pair<int,int> > v[200005];
int centroid;
int ch[200005],vis[200005];
double grd[200005];
double ans[200005];
int Ans;
void dfs(int now,int pre,int sz){
	int i;
	ch[now]=1;
	int maxch=0;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(vis[to]||to==pre) continue;
		dfs(to,now,sz);
		maxch=max(maxch,ch[to]);
		ch[now]+=ch[to];
		ch[to]=0;
	}
	maxch=max(maxch,sz-ch[now]);
	if(maxch<=sz/2)
	  centroid=now;
}
int dfs2(int now,int pre){
	int ret=1;
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(vis[to]||to==pre) continue;
		ret+=dfs2(to,now);
	}
	return ret;
}
void gradi(int now,int pre,long long int len){
	grd[now]=sqrt(len)*w[now];
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(to==pre) continue;
		gradi(to,now,len+v[now][i].S);
		grd[now]+=grd[to];
	}
}
double getans(int now,int pre,long long int len){
	double ret=sqrt(len)*len*w[now];
	int i;
	for(i=0;i<v[now].size();i++){
		int to=v[now][i].F;
		if(to==pre) continue;
		ret+=getans(to,now,len+v[now][i].S);
	}
	return ret;
}
void entry(int pt,int sz){
	int cent;
	int i;
	dfs(pt,pt,sz);
	ch[pt]=0;
	cent=centroid;
//	printf("%d\n",cent);
	vis[cent]=1;
	gradi(cent,cent,0);
	ans[cent]=getans(cent,cent,0);
	double totgrd=0;
	for(i=0;i<v[cent].size();i++){
		totgrd+=grd[v[cent][i].F];
	}
	for(i=0;i<v[cent].size();i++){
		int ch=v[cent][i].F;
		int find=0;
		if(totgrd-2*grd[ch]<0){
			if(vis[ch]){
			//	printf("ff");
				Ans=ans[ch]<ans[cent]?ch:cent;
				find=1;
				return ;
			}
			else{
				int chsz=dfs2(ch,ch);
			//	printf("%d %d\n",ch,chsz);
				entry(ch,chsz);
			}
		}
		if(!find) Ans=cent;
	}
}
int main(void){
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++){
		scanf("%d",&w[i]);
		ch[i]=0;
		vis[i]=0;
		ans[i]=-1;
	}
	for(i=0;i<n-1;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		v[a].PB(MP(b,c));
		v[b].PB(MP(a,c));
	}
	entry(1,n);
	printf("%d %.8f\n",Ans,ans[Ans]);
	return 0;
}

// ntuj - 9w9jhuu69nh6dx0kdy6ma


//{{{
#include <bits/stdc++.h>
using namespace std;
//types
typedef long long ll;
typedef pair<int,int> pii;
//input
bool SR(int &_x){return scanf("%d",&_x)==1;}bool SR(ll &_x){return scanf("%" PRId64,&_x)==1;}
bool SR(double &_x){return scanf("%lf",&_x)==1;}bool SR(char *_s){return scanf("%s",_s)==1;}
bool RI(){return true;}
template<typename I,typename... T>bool RI(I &_x,T&... _tail){return SR(_x) && RI(_tail...);}
//output
void SP(const int _x){printf("%d",_x);}void SP(const ll _x){printf("%" PRId64,_x);}
void SP(const double _x){printf("%.16lf",_x);}void SP(const char *s){printf("%s",s);}
void PL(){puts("");}
template<typename I,typename... T>void PL(const I _x,const T... _tail)
{SP(_x);if(sizeof...(_tail)) putchar(' ');PL(_tail...);}
//macro
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define pb push_back
#define mkp make_pair
#define F first
#define S second
//debug
#ifdef darry140
template<typename I>
void _DOING(const char *_s,I&& _x){cerr<<_s<<"="<<_x<<endl;}//without ','
template<typename I,typename... T>
void _DOING(const char *_s,I&& _x,T&&... _tail)//with ','
{
    int _c=0;
    static const char _bra[]="({[";
    static const char _ket[]=")}]";
    while(*_s!=',' || _c!=0)//eg. mkp(a,b)
    {
        if(strchr(_bra,*_s)) _c++;
        if(strchr(_ket,*_s)) _c--;
        cerr<<*_s++;
    }
    cerr<<"="<<_x<<", ";
    _DOING(_s+1,_tail...);
}
#define debug(...) do{\
    fprintf(stderr,"%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__,__VA_ARGS__);\
}while(0)
template<typename It>
ostream& _OUTC(ostream &_s,It _b,It _e)//container
{
    _s<<"{";
    for(auto _it=_b;_it!=_e;_it++) _s<<(_it==_b?"":" ")<<*_it;
    _s<<"}";
    return _s;
}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const pair<A,B> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const map<A,B> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const set<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const vector<T> &_c){return _OUTC(_s,ALL(_c));}
#else
#define debug(...)
#endif
//}}}
const int maxn=2e5+5;
int n,w[maxn];
vector<pii> edge[maxn];
void read()
{
    RI(n);
    REP1(i,1,n) RI(w[i]);
    REP(i,n-1)
    {
        int a,b,l;
        RI(a,b,l);
        edge[a].pb(mkp(b,l));
        edge[b].pb(mkp(a,l));
    }
}
bitset<maxn> del;
int par[maxn],siz[maxn];
int dfs2(int u,int p)
{
    par[u]=p;siz[u]=1;
    for(auto v:edge[u]) if(!del[v.F] && v.F!=p)
        siz[u]+=dfs2(v.F,u);
    return siz[u];
}
void dfs3(int u,int &ans,int &bw,const int &ful)
{
    int me=ful-siz[u];
    for(auto v:edge[u]) if(!del[v.F] && v.F!=par[u])
        dfs3(v.F,ans,bw,ful),me=max(me,siz[v.F]);
    if(me<bw) bw=me,ans=u;
}
double dfs4(int u,int p,ll dis)
{
    double ans=w[u]*sqrt(dis);
    for(auto e:edge[u]) if(e.F!=p)
        ans+=dfs4(e.F,u,dis+e.S);
    return ans;
}
void dfs5(int u,int p)
{
    del[u]=1;debug("DEL",u);
    for(auto e:edge[u]) if(e.F!=p)
        dfs5(e.F,u);
}
void dfs1(int u)
{
    dfs2(u,0);
    int tmp=siz[u];
    dfs3(u,u,tmp,siz[u]);
    dfs2(u,0);
    debug(u);
    if(siz[u]<=2) return;

    vector<double> dlt;
    for(auto e:edge[u])
        dlt.pb(dfs4(e.F,u,e.S));

    double sum=0;
    for(auto x:dlt) sum+=x;
    int pi=-1;double lo=sum;
    REP(i,SZ(dlt)) if(sum-2*dlt[i]<lo)
        lo=sum-2*dlt[i],pi=i;

    debug(dlt,lo,pi);
    if(lo>=0){del.set();del[u]=0;return;}
    REP(i,SZ(dlt)) if(i!=pi)
        dfs5(edge[u][i].F,u);
    dfs1(u);
}
void build()
{
    dfs1(1);
}
double dfs6(int u,int p,ll dis)
{
    double ans=w[u]*dis*sqrt(dis);
    for(auto e:edge[u]) if(e.F!=p)
        ans+=dfs6(e.F,u,dis+e.S);
    return ans;
}
void sol()
{
    int u=1;double ans=dfs6(1,0,0);
    REP1(i,1,n) if(!del[i])
    {
        debug(i);
        double cur=dfs6(i,0,0);
        if(cur<ans) ans=cur,u=i;
    }
    PL(u,ans);
}
int main()
{
    read();
    build();
    sol();
    return 0;
}

/*End Of File*/

// ntuj - m3gy5hyskx2wjgi77eejx


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,w[N],i,j,k,l,head[N],adj[N],nxt[N],len[N],root,Head[N],Adj[N],Nxt[N],sz[N],mx[N],pt[N];
bool v[N];
void Dfs(int x,int dad,int size)
{
	sz[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,size);
			sz[x]+=sz[adj[y]];
			mx[x]=max(mx[x],sz[adj[y]]);
		}
	mx[x]=max(mx[x],size-sz[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
int dfs(int x,int size)
{
	root=0;
	Dfs(x,-1,size);
	v[root]=true;
	int rtn=root;
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
		{
			int z=dfs(adj[y],sz[adj[y]]);
			Adj[++l]=z;
			Nxt[l]=Head[rtn];
			Head[rtn]=l;
			pt[l]=adj[y];
		}
	return rtn;
}
long double dzx(int x,int dad,int d)
{
	long double rtn=sqrt(d)*w[x]*d;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
			rtn+=dzx(adj[y],x,d+len[y]);
	return rtn;
}
void work(int x)
{
	int i=x;
	long double w=dzx(x,-1,0);
	for(int y=Head[x];y;y=Nxt[y])
	{
		long double z=dzx(pt[y],-1,0);
		if(z<w)
		{
			i=Adj[y];
			w=z;
			break;
		}
	}
	if(i==x)
	{
		printf("%d %.12lf",x,(double)w);
		return;
	}
	work(i);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	root=dfs(1,n);
	work(root);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,w[N],i,j,k,l,head[N],adj[N],nxt[N],len[N],root,Head[N],Adj[N],Nxt[N],sz[N],mx[N],pt[N];
bool v[N];
void Dfs(int x,int dad,int size)
{
	sz[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,size);
			sz[x]+=sz[adj[y]];
			mx[x]=max(mx[x],sz[adj[y]]);
		}
	mx[x]=max(mx[x],size-sz[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
int dfs(int x,int size)
{
	root=0;
	Dfs(x,-1,size);
	v[root]=true;
	int rtn=root;
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
		{
			Adj[++l]=dfs(adj[y],sz[adj[y]]);
			Nxt[l]=Head[rtn];
			Head[rtn]=l;
			pt[l]=adj[y];
		}
	return rtn;
}
long double dzx(int x,int dad,int d)
{
	long double rtn=sqrt(d)*w[x]*d;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
			rtn+=dzx(adj[y],x,d+len[y]);
	return rtn;
}
void work(int x)
{
	int i=x;
	long double w=dzx(x,-1,0);
	for(int y=Head[x];y;y=Nxt[y])
	{
		long double z=dzx(pt[y],-1,0);
		if(z<w)
		{
			i=Adj[y];
			w=z;
		}
	}
	if(i==x)
	{
		printf("%d %.12lf",x,(double)w);
		return;
	}
	work(i);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	root=dfs(1,n);
	work(root);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,w[N],i,j,k,l,head[N],adj[N],nxt[N],len[N],root,Head[N],Adj[N],Nxt[N],sz[N],mx[N],pt[N];
bool v[N];
void Dfs(int x,int dad,int size)
{
	sz[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,size);
			sz[x]+=sz[adj[y]];
			mx[x]=max(mx[x],sz[adj[y]]);
		}
	mx[x]=max(mx[x],size-sz[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
int dfs(int x,int size)
{
	root=0;
	Dfs(x,-1,size);
	v[root]=true;
	int rtn=root;
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
		{
			int z=dfs(adj[y],sz[adj[y]]);
			Adj[++l]=z;
			Nxt[l]=Head[rtn];
			Head[rtn]=l;
			pt[l]=adj[y];
		}
	return rtn;
}
long double dzx(int x,int dad,int d)
{
	long double rtn=sqrt(d)*w[x]*d;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
			rtn+=dzx(adj[y],x,d+len[y]);
	return rtn;
}
void work(int x)
{
	int i=x;
	long double w=dzx(x,-1,0);
	for(int y=Head[x];y;y=Nxt[y])
	{
		long double z=dzx(pt[y],-1,0);
		if(z<w)
		{
			i=Adj[y];
			w=z;
		}
	}
	if(i==x)
	{
		printf("%d %.12lf",x,(double)w);
		return;
	}
	work(i);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	root=dfs(1,n);
	work(root);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,w[N],i,j,k,l,head[N],adj[N],nxt[N],len[N],root,Head[N],Adj[N],Nxt[N],sz[N],mx[N],pt[N],ans1;
bool v[N];
long double dao[N],ans2;
void Dfs(int x,int dad,int size)
{
	sz[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,size);
			sz[x]+=sz[adj[y]];
			mx[x]=max(mx[x],sz[adj[y]]);
		}
	mx[x]=max(mx[x],size-sz[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
int dfs(int x,int size)
{
	root=0;
	Dfs(x,-1,size);
	v[root]=true;
	int rtn=root;
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
		{
			int z=dfs(adj[y],sz[adj[y]]);
			Adj[++l]=z;
			Nxt[l]=Head[rtn];
			Head[rtn]=l;
			pt[l]=adj[y];
		}
	return rtn;
}
long double dzx(int x,int dad,int d)
{
	long double rtn=sqrt(d)*w[x]*d;
	dao[x]=1.5*sqrt(d)*w[x];
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			rtn+=dzx(adj[y],x,d+len[y]);
			dao[x]+=dao[adj[y]];
		}
	return rtn;
}
void work(int x)
{
	int y;
	long double w=dzx(x,-1,0);
	for(y=Head[x];y;y=Nxt[y])
		if(dao[x]-2*dao[pt[y]]<0)
			break;
	if(w<ans2)
	{
		ans1=x;
		ans2=w;
	}
	if(y)
		work(Adj[y]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	root=dfs(1,n);
	ans2=1e50;
	work(root);
	printf("%d %.12lf",ans1,(double)ans2);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=500005;
int n,w[N],i,j,k,l,head[N],adj[N],nxt[N],len[N],root,Head[N],Adj[N],Nxt[N],sz[N],mx[N],pt[N];
bool v[N];
long double keke[N];
void Dfs(int x,int dad,int size)
{
	sz[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,size);
			sz[x]+=sz[adj[y]];
			mx[x]=max(mx[x],sz[adj[y]]);
		}
	mx[x]=max(mx[x],size-sz[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
int dfs(int x,int size)
{
	root=0;
	Dfs(x,-1,size);
	v[root]=true;
	int rtn=root;
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
		{
			int z=dfs(adj[y],sz[adj[y]]);
			Adj[++l]=z;
			Nxt[l]=Head[rtn];
			Head[rtn]=l;
			pt[l]=adj[y];
		}
	return rtn;
}
void dzx(int x,int dad,int d)
{
	keke[x]=sqrt(d)*w[x]*d;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dzx(adj[y],x,d+len[y]);
			keke[x]+=keke[adj[y]];
		}
}
void work(int x)
{
	dzx(x,-1,0);
	int i=0;
	for(int y=Head[x];y;y=Nxt[y])
		if(i==0||keke[pt[y]]>keke[pt[i]])
			i=y;
	long double w=keke[x];
	if(i)
		dzx(pt[i],-1,0);
	if(i==0||w<keke[pt[i]])
	{
		printf("%d %.12lf",x,(double)w);
		return;
	}
	work(Adj[i]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	root=dfs(1,n);
	work(root);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define FOR(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define EXIT(...) printf(__VA_ARGS__), exit(0)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long LL;

template<typename T> T &Read(T &x)
{
	static char c;
	while (!isdigit(c = getchar()));
	x = c - '0';
	while (isdigit(c = getchar())) (x *= 10) += c - '0';
	return x;
}

const int maxn = 200000;

struct edge
{
	int id, g, nxt;

	edge() { }
	edge(const int &_id, const int &_g, const int &_nxt): id(_id), g(_g), nxt(_nxt) { }

};

edge e[(maxn << 1) + 5];
int en = 0;
int st[maxn + 5];

inline void add_edge(const int &x, const int &y, const int &z)
{
	e[en] = edge(y, z, st[x]), st[x] = en++;
}

inline void del_edge(const int &x, const int &y)
{
	for (int *i = st + x; *i != -1; i = &e[*i].nxt)
		if (e[*i].id == y)
		{
			*i = e[*i].nxt;
			break;
		}
}

int n;
int w[maxn + 5];

int ans;

double ansval;

int sz[maxn + 5];
int Max[maxn + 5];

int all[maxn + 5], alln = 0;

bool vis[maxn + 5];

void pre_dfs(const int &x, const int &f = -1)
{
	all[alln++] = x;
	sz[x] = 1;
	Max[x] = 0;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		if (vis[y]) continue;
		pre_dfs(y, x);
		sz[x] += sz[y];
		Max[x] = max(Max[x], sz[y]);
	}
}

double sum = 0;
int dep[maxn + 5];

bool flag;

int rt;

void dfs(const int &x, const int &f = -1)
{
	sum += (double)w[x] * sqrt((double)dep[x]);
	if (x == rt) flag = 1;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		if (vis[y]) continue;
		dep[y] = dep[x] + e[i].g;
		dfs(y, x);
	}
}

double tmp[maxn + 5];

void calc(const int &x, const int &f = -1, const int &dep = 0)
{
	sum += (double)w[x] * dep * sqrt((double)dep);
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		calc(y, x, dep + e[i].g);
	}
}

void update(const int &x)
{
	sum = 0;
	calc(x);
	if (ans == -1 || sum < ansval) ans = x, ansval = sum;
}

void work(const int &rt)
{
	::rt = rt;
	alln = 0;
	pre_dfs(rt);

	int x = -1;
	REP(i, 0, alln)
	{
		const int &y = all[i];
		Max[y] = max(Max[y], alln - sz[y]);
		if (x == -1 || Max[y] < Max[x]) x = y;
	}
	update(x);
	if (alln == 1) return;

	double cnt = 0;
	int rt_p = -1;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (vis[y]) continue;
		dep[y] = e[i].g;
		sum = 0;
		flag = 0;
		dfs(y, x);
		if (flag)
		{
			rt_p = y;
			continue;
		}
		cnt += sum;
		tmp[y] = sum;
	}

	int Min = -1;
	double Minval = 1e100;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (vis[y]) continue;
		if (y == rt_p) continue;
		double lyc = cnt - 2 * tmp[y];
		if (Min == -1 || lyc < Minval) Min = y, Minval = lyc;
	}

	sum = 0;
	calc(Min);
	Minval = sum;

	sum = 0;
	calc(rt_p);
	if (sum < Minval) Min = rt_p, Minval = sum;

	vis[x] = 1;
	work(Min);

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	memset(st, -1, sizeof st), en = 0;
	REP(i, 0, n) scanf("%d", w + i);
	REP(i, 0, n - 1)
	{
		static int x, y, z;
		scanf("%d%d%d", &x, &y, &z), --x, --y;
		add_edge(x, y, z), add_edge(y, x, z);
	}
	ans = -1;
	work(0);
	printf("%d ", ans + 1);
	printf("%.16f\n", ansval);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define FOR(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define EXIT(...) printf(__VA_ARGS__), exit(0)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long LL;

template<typename T> T &Read(T &x)
{
	static char c;
	while (!isdigit(c = getchar()));
	x = c - '0';
	while (isdigit(c = getchar())) (x *= 10) += c - '0';
	return x;
}

const int maxn = 200000;

struct edge
{
	int id, g, nxt;

	edge() { }
	edge(const int &_id, const int &_g, const int &_nxt): id(_id), g(_g), nxt(_nxt) { }

};

edge e[(maxn << 1) + 5];
int en = 0;
int st[maxn + 5];

inline void add_edge(const int &x, const int &y, const int &z)
{
	e[en] = edge(y, z, st[x]), st[x] = en++;
}

inline void del_edge(const int &x, const int &y)
{
	for (int *i = st + x; *i != -1; i = &e[*i].nxt)
		if (e[*i].id == y)
		{
			*i = e[*i].nxt;
			break;
		}
}

int n;
int w[maxn + 5];

int ans;

double ansval;

int sz[maxn + 5];
int Max[maxn + 5];

int all[maxn + 5], alln = 0;

bool vis[maxn + 5];

void pre_dfs(const int &x, const int &f = -1)
{
	all[alln++] = x;
	sz[x] = 1;
	Max[x] = 0;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		if (vis[y]) continue;
		pre_dfs(y, x);
		sz[x] += sz[y];
		Max[x] = max(Max[x], sz[y]);
	}
}

double sum = 0;
int dep[maxn + 5];

int rt;

void dfs(const int &x, const int &f = -1)
{
	sum += (double)w[x] * sqrt((double)dep[x]);
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		dep[y] = dep[x] + e[i].g;
		dfs(y, x);
	}
}

void calc(const int &x, const int &f = -1, const int &dep = 0)
{
	sum += (double)w[x] * dep * sqrt((double)dep);
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (y == f) continue;
		calc(y, x, dep + e[i].g);
	}
}

void update(const int &x)
{
	sum = 0;
	calc(x);
	if (ans == -1 || sum < ansval) ans = x, ansval = sum;
}

void work(const int &rt)
{
	::rt = rt;
	alln = 0;
	pre_dfs(rt);

	int x = -1;
	REP(i, 0, alln)
	{
		const int &y = all[i];
		Max[y] = max(Max[y], alln - sz[y]);
		if (x == -1 || Max[y] < Max[x]) x = y;
	}
	update(x);
	if (alln == 1) return;

	int Max = -1;
	double Maxval;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		const int &y = e[i].id;
		if (vis[y]) continue;
		dep[y] = e[i].g;
		sum = 0;
		dfs(y, x);
		if (Max == -1 || sum > Maxval) Max = y, Maxval = sum;
	}

	vis[x] = 1;
	work(Max);

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	memset(st, -1, sizeof st), en = 0;
	REP(i, 0, n) scanf("%d", w + i);
	REP(i, 0, n - 1)
	{
		static int x, y, z;
		scanf("%d%d%d", &x, &y, &z), --x, --y;
		add_edge(x, y, z), add_edge(y, x, z);
	}
	ans = -1;
	work(0);
	printf("%d ", ans + 1);
	printf("%.16f\n", ansval);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define FOR(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define EXIT(...) printf(__VA_ARGS__), exit(0)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long LL;

template<typename T> T &Read(T &x)
{
    static char c;
    while (!isdigit(c = getchar()));
    x = c - '0';
    while (isdigit(c = getchar())) (x *= 10) += c - '0';
    return x;
}

const int maxn = 200000;

struct edge
{
    int id, g, nxt;

    edge() { }
    edge(const int &_id, const int &_g, const int &_nxt): id(_id), g(_g), nxt(_nxt) { }

};

edge e[(maxn << 1) + 5];
int en = 0;
int st[maxn + 5];

inline void add_edge(const int &x, const int &y, const int &z)
{
    e[en] = edge(y, z, st[x]), st[x] = en++;
}

inline void del_edge(const int &x, const int &y)
{
    for (int *i = st + x; *i != -1; i = &e[*i].nxt)
        if (e[*i].id == y)
        {
            *i = e[*i].nxt;
            break;
        }
}

int n;
int w[maxn + 5];

int ans;

double ansval;

int sz[maxn + 5];
int Max[maxn + 5];

int all[maxn + 5], alln = 0;

bool vis[maxn + 5];

void pre_dfs(const int &x, const int &f = -1)
{
    all[alln++] = x;
    sz[x] = 1;
    Max[x] = 0;
    for (int i = st[x]; i != -1; i = e[i].nxt)
    {
        const int &y = e[i].id;
        if (y == f) continue;
        if (vis[y]) continue;
        pre_dfs(y, x);
        sz[x] += sz[y];
        Max[x] = max(Max[x], Max[y]);
    }
}

double sum = 0;
int dep[maxn + 5];

void dfs(const int &x, const int &f = -1)
{
    sum += (double)w[x] * sqrt((double)dep[x]);
    for (int i = st[x]; i != -1; i = e[i].nxt)
    {
        const int &y = e[i].id;
        if (y == f) continue;
        if (vis[y]) continue;
        dep[y] = dep[x] + e[i].g;
        dfs(y, x);
    }
}

double tmp[maxn + 5];

void calc(const int &x, const int &f = -1, const int &dep = 0)
{
    sum += (double)w[x] * dep * sqrt((double)dep);
    for (int i = st[x]; i != -1; i = e[i].nxt)
    {
        const int &y = e[i].id;
        if (y == f) continue;
        calc(y, x, dep + e[i].g);
    }
}

void update(const int &x)
{
    sum = 0;
    calc(x);
    if (ans == -1 || sum < ansval) ans = x, ansval = sum;
}

void work(const int &rt)
{
    update(rt);

    alln = 0;
    pre_dfs(rt);
    if (alln == 1) return;

    int x = -1;
    REP(i, 0, alln)
    {
        const int &y = all[i];
        Max[y] = max(Max[y], alln - sz[y]);
        if (x == -1 || Max[y] < Max[x]) x = y;
    }

    double cnt = 0;
    for (int i = st[x]; i != -1; i = e[i].nxt)
    {
        const int &y = e[i].id;
        if (vis[y]) continue;
        dep[y] = e[i].g;
        sum = 0;
        dfs(y, x);
        cnt += sum;
        tmp[y] = sum;
    }

    int Min = -1;
    double Minval;
    for (int i = st[x]; i != -1; i = e[i].nxt)
    {
        const int &y = e[i].id;
        if (vis[y]) continue;
        double lyc = cnt -= 2 * tmp[y];
        if (Min == -1 || lyc < Minval) Min = y, Minval = lyc;
    }

    vis[x] = 1;
    work(Min);

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    memset(st, -1, sizeof st), en = 0;
    REP(i, 0, n) scanf("%d", w + i);
    REP(i, 0, n - 1)
    {
        static int x, y, z;
        scanf("%d%d%d", &x, &y, &z), --x, --y;
        add_edge(x, y, z), add_edge(y, x, z);
    }
    ans = -1;
    work(0);
    printf("%d ", ans + 1);
    printf("%.16f\n", ansval);
    return 0;
}