全部re,求助
查看原帖
全部re,求助
138106
tgs9311楼主2020/10/31 21:19
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[2000001],maxt123=-10000000;
int biggest123;
vector<long long> g[2000001];
signed main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		if(n==1)
		{
			cin>>m;
			cout<<1;
		}
		for(int i=1; i<=n; i++)
		{
			cin>>a[i];
			if(a[i]>maxt123)
			{
				biggest123=i;
				maxt123=a[i];
			}
		}
		for(int i=1; i<n; i++)
		{
			long long ddx,ddy;
			cin>>ddx>>ddy;
			g[ddx].push_back(ddy);
			g[ddy].push_back(ddx);
		}
		long long to,max2123=-1;
		for(int i=0; i<g[biggest123].size(); i++)
		{
			if((a[g[biggest123][i]]>max2123)||(a[g[biggest123][i]]==max2123&&g[biggest123][i]<to))
			{
				to=g[biggest123][i];
				max2123=a[to];
			}
		}
		if(m<a[biggest123]-a[to])
		{
			cout<<biggest123<<endl;
		}
		else
		{
			m=m-(a[biggest123]-a[to]);
			if(biggest123<to)
			{
				if(m%2==0)
				{
					cout<<biggest123<<endl;
				}
				else
				{
					cout<<to<<endl;
				}
			}
			else
			{
				if(m%2==0)
				{
					cout<<to<<endl;
				}
				else
				{
					cout<<biggest123<<endl;
				}
			}
		}
		for(int i=1; i<=2000000; i++)
		{
			g[i].clear();
		}
		maxt123=-100000000;
	}

}

蒟蒻求教,不应该re的啊

2020/10/31 21:19
加载中...