55求助不知道错哪
查看原帖
55求助不知道错哪
250146
wtq12138楼主2020/11/2 19:31
#include<bits/stdc++.h>
using namespace std;
unsigned long long  n, cnt,T, head[2000010],day,hg[2000010];
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 * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
struct b
{
	int to, next;
}e[2000010];
void add(int u, int v)
{
	cnt++;
	e[cnt].to = v;
	e[cnt].next = head[u];
	head[u] = cnt;
}
int main()
{
	cin >> T;
	while (T--)
	{
		memset(head,0, sizeof(head));
		memset(hg, 0, sizeof(hg));
		n = read();
		day = read();
		int maxhg = 0, maxnumber=1;
		for (int i = 1; i <= n; i++)
		{
			hg[i]  = read();
			if (maxhg < hg[i]||maxhg==hg[i]&&maxnumber>i)
				maxnumber =i, maxhg = hg[i];
		}
		for (int i = 1; i <= n - 1; i++)
		{
			int x, y;
			x = read();
			y = read();
			add(x, y);
			add(y, x);
		}
		if (n==1)
		{
			cout << maxnumber << endl;
			continue;
		}
		int  maxnumber2 = e[head[maxnumber]].to;
		for (int j = head[maxnumber]; j; j = e[j].next)
		{
			int y = e[j].to;
			if (hg[y] >hg[maxnumber2])
				 maxnumber2 = y;
		}
		if (maxhg - hg[maxnumber2]>day)
		{
			cout << maxnumber << endl;
			continue;
		}
		long long tmp = day - maxhg + hg[maxnumber2];
		if (tmp % 2 )
			cout << max(maxnumber, maxnumber2) << endl;
		else
			cout << min(maxnumber, maxnumber2) << endl;
	}
	return 0;
}  
2020/11/2 19:31
加载中...