106462024-04-07 17:51:10111XORfa visszatércpp17Wrong answer 0/100490ms6204 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;
	if(N>1000||Q>1000)exit(1);
	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;
	multiset<int>ans;
	vector<int>u(N+1);
	vector<vector<int>>p(N+1);
	while(Q--){
		int a;
		cin>>a;
		if(s.count(a)){
			s.erase(a);
			for(int x:p[a]){
				int y=x;
				for(int z:s){
					if((v[x]^v[z])>(v[x]^v[y])){
						y=z;
					}
				}
				ans.erase(ans.find(v[x]^v[u[x]]));
				u[x]=y;
				if(y!=x){
					p[y].push_back(x);
				}
				ans.insert(v[x]^v[y]);
			}
			p[a].clear();
		}
		else{
			int x=a;
			int y=x;
			for(int z:s){
				if((v[x]^v[z])>(v[x]^v[y])){
					y=z;
				}
			}
			ans.insert(v[x]^v[y]);
			u[x]=y;
			if(y!=x){
				p[y].push_back(x);
			}
			s.insert(x);
		}
		cout<<*--ans.end()<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2056 KiB
subtask20/11
3Wrong answer3ms2248 KiB
4Wrong answer3ms2592 KiB
5Wrong answer3ms2548 KiB
6Wrong answer3ms2668 KiB
7Wrong answer3ms3036 KiB
8Wrong answer3ms3024 KiB
9Wrong answer3ms2984 KiB
10Wrong answer3ms3252 KiB
11Wrong answer3ms3580 KiB
12Wrong answer3ms3788 KiB
13Wrong answer3ms3864 KiB
subtask30/13
14Runtime error2ms3872 KiB
15Runtime error2ms3824 KiB
16Runtime error2ms3892 KiB
17Runtime error2ms3904 KiB
18Runtime error2ms3812 KiB
19Runtime error3ms3924 KiB
20Runtime error3ms4272 KiB
21Runtime error3ms4220 KiB
22Runtime error3ms4336 KiB
23Runtime error3ms4332 KiB
subtask40/17
24Wrong answer6ms4644 KiB
25Wrong answer4ms4572 KiB
26Wrong answer7ms4552 KiB
27Wrong answer8ms4584 KiB
28Accepted8ms4844 KiB
29Wrong answer4ms4648 KiB
30Wrong answer6ms4652 KiB
31Wrong answer6ms4832 KiB
32Wrong answer479ms5940 KiB
33Wrong answer490ms5932 KiB
34Wrong answer477ms6196 KiB
35Wrong answer476ms6204 KiB
subtask50/59
36Runtime error3ms4756 KiB
37Runtime error3ms4844 KiB
38Runtime error3ms4656 KiB
39Runtime error3ms4648 KiB
40Runtime error3ms4652 KiB
41Runtime error3ms4752 KiB
42Runtime error2ms4648 KiB
43Runtime error2ms4752 KiB
44Runtime error2ms4752 KiB
45Runtime error2ms4752 KiB
46Runtime error3ms4644 KiB
47Runtime error3ms4752 KiB
48Runtime error3ms4856 KiB
49Runtime error3ms4548 KiB