106442024-04-07 17:46:44111XORfa visszatércpp17Wrong answer 0/1001.587s20348 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;
	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;
				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
2Accepted3ms2048 KiB
subtask20/11
3Wrong answer3ms2296 KiB
4Wrong answer3ms2628 KiB
5Wrong answer3ms2960 KiB
6Wrong answer3ms2892 KiB
7Wrong answer3ms3092 KiB
8Wrong answer3ms3188 KiB
9Wrong answer3ms3276 KiB
10Wrong answer3ms3412 KiB
11Wrong answer3ms3756 KiB
12Wrong answer3ms3976 KiB
13Wrong answer3ms3920 KiB
subtask30/13
14Wrong answer61ms18436 KiB
15Wrong answer64ms18316 KiB
16Time limit exceeded1.574s10628 KiB
17Time limit exceeded1.57s10524 KiB
18Time limit exceeded1.562s10376 KiB
19Time limit exceeded1.567s10632 KiB
20Time limit exceeded1.557s10800 KiB
21Time limit exceeded1.587s10988 KiB
22Wrong answer64ms19360 KiB
23Wrong answer67ms19324 KiB
subtask40/17
24Wrong answer6ms5228 KiB
25Wrong answer4ms5488 KiB
26Wrong answer7ms5580 KiB
27Wrong answer8ms5620 KiB
28Accepted8ms5748 KiB
29Wrong answer4ms5544 KiB
30Wrong answer6ms5720 KiB
31Wrong answer6ms5756 KiB
32Wrong answer16ms5708 KiB
33Wrong answer16ms5672 KiB
34Wrong answer16ms5672 KiB
35Wrong answer16ms5688 KiB
subtask50/59
36Time limit exceeded1.55s11568 KiB
37Time limit exceeded1.534s11716 KiB
38Time limit exceeded1.567s11576 KiB
39Time limit exceeded1.562s11512 KiB
40Time limit exceeded1.554s11712 KiB
41Time limit exceeded1.562s11752 KiB
42Time limit exceeded1.577s11928 KiB
43Time limit exceeded1.557s11936 KiB
44Time limit exceeded1.577s12016 KiB
45Wrong answer163ms20348 KiB
46Time limit exceeded1.559s12068 KiB
47Time limit exceeded1.565s12280 KiB
48Time limit exceeded1.546s12604 KiB
49Time limit exceeded1.57s12464 KiB