样例过,全wa,求调试
查看原帖
样例过,全wa,求调试
1307816
asdasd1297楼主2024/11/7 18:27
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,x[2001000];
vector<int> ed;
void solve() {
	int st=0,mx=0;
	cin>>n>>m;
	ed.clear();
	if(n==1) {
		cout<<1<<endl;
		return;
	}
	for(int i=1; i<=n; i++) {
		cin>>x[i];
		if(mx<x[i]) {
			mx=x[i];
			st=i;
		}
	}
	for(int i=1,a,b; i<n; i++) {
		cin>>a>>b;
		if(a==st||b==st) {
			ed.push_back(a+b-st);
		}
	}
	mx=0;
	int e=0;
	for(int i=0; i<ed.size(); i++) {
		if(mx<x[ed[i]]||(mx==x[ed[i]]&&ed[i]<e)) {
			mx=x[ed[i]];
			e=ed[i];
		}
	}
	if(m<x[st]-x[e]) {
		cout<<st<<endl;
		return;
	}
	m-=x[st]-x[e];
	cout<<(m%2?max(st,e):min(st,e))<<endl;
	return;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)solve();
	return 0;
}
2024/11/7 18:27
加载中...