106432024-04-07 16:56:35111XORfa visszatércpp17Time limit exceeded 11/1001.582s34132 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,Q;
	cin>>N>>Q;
	vector<vector<pair<int,int>>>g(N+1);
	for(int i=0;i<N-1;i++){
		int a,b,w;
		cin>>a>>b>>w;
		g[a].emplace_back(b,w);
		g[b].emplace_back(a,w);
	}
	vector<int>v(N+1);
	auto dfs=[&](auto self,int i,int p,int x)->void{
		v[i]=x;
		for(auto[j,w]:g[i]){
			if(j==p){
				continue;
			}
			self(self,j,i,x^w);
		}
	};
	dfs(dfs,1,0,0);
	set<int>s;
	while(Q--){
		int x;
		cin>>x;
		if(!s.insert(x).second){
			s.erase(x);
		}
		int ans=0;
		for(int i:s){
			for(int j:s){
				ans=max(ans,v[i]^v[j]);
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2056 KiB
subtask211/11
3Accepted3ms2244 KiB
4Accepted3ms2472 KiB
5Accepted4ms2448 KiB
6Accepted3ms2536 KiB
7Accepted3ms2584 KiB
8Accepted3ms2928 KiB
9Accepted3ms2884 KiB
10Accepted4ms3144 KiB
11Accepted4ms3104 KiB
12Accepted4ms3104 KiB
13Accepted4ms3108 KiB
subtask30/13
14Accepted46ms12552 KiB
15Accepted61ms13480 KiB
16Time limit exceeded1.572s9704 KiB
17Time limit exceeded1.582s10548 KiB
18Time limit exceeded1.578s11784 KiB
19Time limit exceeded1.547s12808 KiB
20Time limit exceeded1.55s13720 KiB
21Time limit exceeded1.559s14836 KiB
22Accepted61ms20652 KiB
23Accepted61ms21652 KiB
subtask40/17
24Accepted254ms13732 KiB
25Accepted57ms13796 KiB
26Accepted663ms13776 KiB
27Accepted1.358s13712 KiB
28Time limit exceeded1.567s13056 KiB
29Accepted201ms14064 KiB
30Accepted312ms14108 KiB
31Accepted317ms14372 KiB
32Time limit exceeded1.57s13720 KiB
33Time limit exceeded1.582s13744 KiB
34Time limit exceeded1.565s14576 KiB
35Time limit exceeded1.557s13820 KiB
subtask50/59
36Time limit exceeded1.567s19224 KiB
37Time limit exceeded1.575s20348 KiB
38Time limit exceeded1.56s21468 KiB
39Time limit exceeded1.56s22804 KiB
40Time limit exceeded1.564s24300 KiB
41Time limit exceeded1.567s25572 KiB
42Time limit exceeded1.547s26740 KiB
43Time limit exceeded1.572s28072 KiB
44Time limit exceeded1.544s29328 KiB
45Time limit exceeded1.564s30816 KiB
46Time limit exceeded1.559s31720 KiB
47Time limit exceeded1.567s32500 KiB
48Time limit exceeded1.539s33456 KiB
49Time limit exceeded1.544s34132 KiB