10646 | 2024-04-07 17:51:10 | 111 | XORfa visszatér | cpp17 | Wrong answer 0/100 | 490ms | 6204 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Wrong answer | 3ms | 2248 KiB | ||||
4 | Wrong answer | 3ms | 2592 KiB | ||||
5 | Wrong answer | 3ms | 2548 KiB | ||||
6 | Wrong answer | 3ms | 2668 KiB | ||||
7 | Wrong answer | 3ms | 3036 KiB | ||||
8 | Wrong answer | 3ms | 3024 KiB | ||||
9 | Wrong answer | 3ms | 2984 KiB | ||||
10 | Wrong answer | 3ms | 3252 KiB | ||||
11 | Wrong answer | 3ms | 3580 KiB | ||||
12 | Wrong answer | 3ms | 3788 KiB | ||||
13 | Wrong answer | 3ms | 3864 KiB | ||||
subtask3 | 0/13 | ||||||
14 | Runtime error | 2ms | 3872 KiB | ||||
15 | Runtime error | 2ms | 3824 KiB | ||||
16 | Runtime error | 2ms | 3892 KiB | ||||
17 | Runtime error | 2ms | 3904 KiB | ||||
18 | Runtime error | 2ms | 3812 KiB | ||||
19 | Runtime error | 3ms | 3924 KiB | ||||
20 | Runtime error | 3ms | 4272 KiB | ||||
21 | Runtime error | 3ms | 4220 KiB | ||||
22 | Runtime error | 3ms | 4336 KiB | ||||
23 | Runtime error | 3ms | 4332 KiB | ||||
subtask4 | 0/17 | ||||||
24 | Wrong answer | 6ms | 4644 KiB | ||||
25 | Wrong answer | 4ms | 4572 KiB | ||||
26 | Wrong answer | 7ms | 4552 KiB | ||||
27 | Wrong answer | 8ms | 4584 KiB | ||||
28 | Accepted | 8ms | 4844 KiB | ||||
29 | Wrong answer | 4ms | 4648 KiB | ||||
30 | Wrong answer | 6ms | 4652 KiB | ||||
31 | Wrong answer | 6ms | 4832 KiB | ||||
32 | Wrong answer | 479ms | 5940 KiB | ||||
33 | Wrong answer | 490ms | 5932 KiB | ||||
34 | Wrong answer | 477ms | 6196 KiB | ||||
35 | Wrong answer | 476ms | 6204 KiB | ||||
subtask5 | 0/59 | ||||||
36 | Runtime error | 3ms | 4756 KiB | ||||
37 | Runtime error | 3ms | 4844 KiB | ||||
38 | Runtime error | 3ms | 4656 KiB | ||||
39 | Runtime error | 3ms | 4648 KiB | ||||
40 | Runtime error | 3ms | 4652 KiB | ||||
41 | Runtime error | 3ms | 4752 KiB | ||||
42 | Runtime error | 2ms | 4648 KiB | ||||
43 | Runtime error | 2ms | 4752 KiB | ||||
44 | Runtime error | 2ms | 4752 KiB | ||||
45 | Runtime error | 2ms | 4752 KiB | ||||
46 | Runtime error | 3ms | 4644 KiB | ||||
47 | Runtime error | 3ms | 4752 KiB | ||||
48 | Runtime error | 3ms | 4856 KiB | ||||
49 | Runtime error | 3ms | 4548 KiB |