10650 | 2024-04-07 18:24:18 | 111 | XORfa visszatér | cpp17 | Runtime error 28/100 | 513ms | 5104 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;
vector<set<int>>p(N+1);
multiset<int>ans;
ans.insert(0);
while(Q--){
int x;
cin>>x;
if(s.count(x)){
s.erase(x);
for(int y:p[x]){
p[y].erase(x);
ans.erase(ans.find(v[x]^v[y]));
if(s.size()>1){
int z=y;
for(int a:s){
if((v[y]^v[a])>(v[y]^v[z])){
z=a;
}
}
if(!p[y].count(z)){
ans.insert(v[y]^v[z]);
p[y].insert(z);
p[z].insert(y);
}
}
}
p[x].clear();
}
else{
if(!s.empty()){
int y=x;
for(int a:s){
if((v[x]^v[a])>(v[x]^v[y])){
y=a;
}
}
if(!p[x].count(y)){
ans.insert(v[x]^v[y]);
p[x].insert(y);
p[y].insert(x);
}
}
s.insert(x);
}
// for(int i:ans)cout<<i<<' ';cout<<'\n';
cout<<*--ans.end()<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2016 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 3ms | 2380 KiB | ||||
4 | Accepted | 3ms | 2584 KiB | ||||
5 | Accepted | 3ms | 2548 KiB | ||||
6 | Accepted | 3ms | 2808 KiB | ||||
7 | Accepted | 3ms | 3136 KiB | ||||
8 | Accepted | 3ms | 2976 KiB | ||||
9 | Accepted | 3ms | 3228 KiB | ||||
10 | Accepted | 3ms | 3576 KiB | ||||
11 | Accepted | 3ms | 3636 KiB | ||||
12 | Accepted | 3ms | 3480 KiB | ||||
13 | Accepted | 3ms | 3804 KiB | ||||
subtask3 | 0/13 | ||||||
14 | Runtime error | 3ms | 3788 KiB | ||||
15 | Runtime error | 3ms | 3944 KiB | ||||
16 | Runtime error | 3ms | 4032 KiB | ||||
17 | Runtime error | 3ms | 3928 KiB | ||||
18 | Runtime error | 2ms | 4036 KiB | ||||
19 | Runtime error | 2ms | 4028 KiB | ||||
20 | Runtime error | 2ms | 3924 KiB | ||||
21 | Runtime error | 2ms | 3924 KiB | ||||
22 | Runtime error | 3ms | 4152 KiB | ||||
23 | Runtime error | 2ms | 4236 KiB | ||||
subtask4 | 17/17 | ||||||
24 | Accepted | 6ms | 4604 KiB | ||||
25 | Accepted | 4ms | 4332 KiB | ||||
26 | Accepted | 8ms | 4540 KiB | ||||
27 | Accepted | 8ms | 4664 KiB | ||||
28 | Accepted | 9ms | 5000 KiB | ||||
29 | Accepted | 6ms | 4724 KiB | ||||
30 | Accepted | 7ms | 4648 KiB | ||||
31 | Accepted | 7ms | 4652 KiB | ||||
32 | Accepted | 508ms | 4896 KiB | ||||
33 | Accepted | 513ms | 4852 KiB | ||||
34 | Accepted | 513ms | 4864 KiB | ||||
35 | Accepted | 513ms | 5104 KiB | ||||
subtask5 | 0/59 | ||||||
36 | Runtime error | 2ms | 4528 KiB | ||||
37 | Runtime error | 3ms | 4528 KiB | ||||
38 | Runtime error | 3ms | 4772 KiB | ||||
39 | Runtime error | 2ms | 4760 KiB | ||||
40 | Runtime error | 2ms | 4888 KiB | ||||
41 | Runtime error | 2ms | 4636 KiB | ||||
42 | Runtime error | 2ms | 4528 KiB | ||||
43 | Runtime error | 2ms | 4624 KiB | ||||
44 | Runtime error | 2ms | 4624 KiB | ||||
45 | Runtime error | 2ms | 4464 KiB | ||||
46 | Runtime error | 2ms | 4564 KiB | ||||
47 | Runtime error | 2ms | 4568 KiB | ||||
48 | Runtime error | 2ms | 4560 KiB | ||||
49 | Runtime error | 3ms | 4564 KiB |