106452024-04-07 17:47:52111XORfa visszatércpp17Wrong answer 0/100486ms5940 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;
				p[y].push_back(x);
				ans.insert(v[x]^v[y]);
			}
			p[a].clear();
		}
		else{
			int y=a;
			for(int z:s){
				if((v[a]^v[z])>(v[a]^v[y])){
					y=z;
				}
			}
			ans.insert(v[a]^v[y]);
			u[a]=y;
			p[y].push_back(a);
			s.insert(a);
		}
		cout<<*--ans.end()<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2020 KiB
subtask20/11
3Wrong answer3ms2380 KiB
4Runtime error3ms2424 KiB
5Wrong answer3ms2596 KiB
6Wrong answer3ms2548 KiB
7Wrong answer3ms2672 KiB
8Wrong answer3ms2760 KiB
9Wrong answer3ms2756 KiB
10Wrong answer3ms2900 KiB
11Wrong answer3ms2872 KiB
12Wrong answer3ms2932 KiB
13Wrong answer3ms3020 KiB
subtask30/13
14Runtime error2ms2928 KiB
15Runtime error3ms3072 KiB
16Runtime error2ms3084 KiB
17Runtime error3ms3296 KiB
18Runtime error3ms3272 KiB
19Runtime error3ms3264 KiB
20Runtime error2ms3268 KiB
21Runtime error3ms3500 KiB
22Runtime error3ms3484 KiB
23Runtime error3ms3724 KiB
subtask40/17
24Wrong answer6ms4028 KiB
25Wrong answer4ms4020 KiB
26Wrong answer7ms4048 KiB
27Wrong answer8ms4592 KiB
28Accepted8ms4432 KiB
29Wrong answer4ms4388 KiB
30Wrong answer6ms4428 KiB
31Wrong answer6ms4396 KiB
32Wrong answer472ms5940 KiB
33Wrong answer486ms5892 KiB
34Wrong answer476ms5924 KiB
35Wrong answer474ms5924 KiB
subtask50/59
36Runtime error3ms4336 KiB
37Runtime error2ms4332 KiB
38Runtime error3ms4336 KiB
39Runtime error2ms4432 KiB
40Runtime error3ms4536 KiB
41Runtime error3ms4636 KiB
42Runtime error3ms4764 KiB
43Runtime error3ms4772 KiB
44Runtime error3ms4676 KiB
45Runtime error3ms4676 KiB
46Runtime error3ms4556 KiB
47Runtime error3ms4648 KiB
48Runtime error3ms4552 KiB
49Runtime error3ms4652 KiB