10645 | 2024-04-07 17:47:52 | 111 | XORfa visszatér | cpp17 | Wrong answer 0/100 | 486ms | 5940 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Wrong answer | 3ms | 2380 KiB | ||||
4 | Runtime error | 3ms | 2424 KiB | ||||
5 | Wrong answer | 3ms | 2596 KiB | ||||
6 | Wrong answer | 3ms | 2548 KiB | ||||
7 | Wrong answer | 3ms | 2672 KiB | ||||
8 | Wrong answer | 3ms | 2760 KiB | ||||
9 | Wrong answer | 3ms | 2756 KiB | ||||
10 | Wrong answer | 3ms | 2900 KiB | ||||
11 | Wrong answer | 3ms | 2872 KiB | ||||
12 | Wrong answer | 3ms | 2932 KiB | ||||
13 | Wrong answer | 3ms | 3020 KiB | ||||
subtask3 | 0/13 | ||||||
14 | Runtime error | 2ms | 2928 KiB | ||||
15 | Runtime error | 3ms | 3072 KiB | ||||
16 | Runtime error | 2ms | 3084 KiB | ||||
17 | Runtime error | 3ms | 3296 KiB | ||||
18 | Runtime error | 3ms | 3272 KiB | ||||
19 | Runtime error | 3ms | 3264 KiB | ||||
20 | Runtime error | 2ms | 3268 KiB | ||||
21 | Runtime error | 3ms | 3500 KiB | ||||
22 | Runtime error | 3ms | 3484 KiB | ||||
23 | Runtime error | 3ms | 3724 KiB | ||||
subtask4 | 0/17 | ||||||
24 | Wrong answer | 6ms | 4028 KiB | ||||
25 | Wrong answer | 4ms | 4020 KiB | ||||
26 | Wrong answer | 7ms | 4048 KiB | ||||
27 | Wrong answer | 8ms | 4592 KiB | ||||
28 | Accepted | 8ms | 4432 KiB | ||||
29 | Wrong answer | 4ms | 4388 KiB | ||||
30 | Wrong answer | 6ms | 4428 KiB | ||||
31 | Wrong answer | 6ms | 4396 KiB | ||||
32 | Wrong answer | 472ms | 5940 KiB | ||||
33 | Wrong answer | 486ms | 5892 KiB | ||||
34 | Wrong answer | 476ms | 5924 KiB | ||||
35 | Wrong answer | 474ms | 5924 KiB | ||||
subtask5 | 0/59 | ||||||
36 | Runtime error | 3ms | 4336 KiB | ||||
37 | Runtime error | 2ms | 4332 KiB | ||||
38 | Runtime error | 3ms | 4336 KiB | ||||
39 | Runtime error | 2ms | 4432 KiB | ||||
40 | Runtime error | 3ms | 4536 KiB | ||||
41 | Runtime error | 3ms | 4636 KiB | ||||
42 | Runtime error | 3ms | 4764 KiB | ||||
43 | Runtime error | 3ms | 4772 KiB | ||||
44 | Runtime error | 3ms | 4676 KiB | ||||
45 | Runtime error | 3ms | 4676 KiB | ||||
46 | Runtime error | 3ms | 4556 KiB | ||||
47 | Runtime error | 3ms | 4648 KiB | ||||
48 | Runtime error | 3ms | 4552 KiB | ||||
49 | Runtime error | 3ms | 4652 KiB |