#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 2e5 + 1;
int a[nmax], b[nmax];
int in[nmax];
int out[nmax];
vector <int> t(4 * nmax);
void update(int v, int l, int r, int pos, int val){
if(l > pos || r < pos) return;
if(l == r){
t[v] = val;
return;
}
int m = (l + r) / 2;
update(2 * v, l, m, pos, val);
update(2 * v + 1, m+ 1, r, pos, val);
t[v] = max(t[2 * v], t[2 * v + 1]);
}
int getlast(int v, int l, int r, int st, int fin, int val){
if(l > fin || r < st) return -1;
if(l >= st && r <= fin){
if(t[v] < val) return -1;
while(l != r){
int m = (l + r) / 2;
if(t[2 * v + 1] >= val) v = v * 2 + 1, l = m + 1;
else v = v * 2, r = m;
}
return l;
}
int m = (l + r) / 2;
int u = getlast(2 * v + 1, m + 1, r, st, fin, val);
if(u != -1) return u;
return getlast(2 * v, l, m, st, fin, val);
}
int timer = 1;
int timer1 = 1;
vector <vector <int> > g(nmax);
void dfs(int v, int e = -1){
in[v] = timer++;
for(int to : g[v]){
if(to == e) continue;
dfs(to, v);
}
out[v] = timer1++;
}
int n;
int add(int v, int o){
int u = getlast(1, 1, n, 1, v - 1, o);
a[u] = a[v] + a[u] - b[v];
update(1, 1, n, v, 0);
}
int rem(int v, int o){
int u = getlast(1, 1, n, 1, v, o);
b[v] = a[u];
a[v] = a[u];
update(1, 1, n, v, o);
}
int main(){
#ifndef ONLINE_JUDGE
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
cin >> n;
int m; cin >> m;
int q; cin >> q;
pii ed[n];
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
ed[i] = {u, v};
}
dfs(1);
for(int i= 1; i <= n; i++){
update(1, 1, n, in[i], out[i]);
a[i] = 1;
}
for(int i = 1; i < n; i++){
int &u = ed[i].f, &v = ed[i].s;
if(in[u] < in[v]) swap(u, v);
}
bool cond[n];
fill(cond, cond + n, false);
while(m--){
int x; cin >> x;
int u = ed[x].f;
int v = ed[x].s;
cond[x] ^= 1;
if(cond[x]) add(in[u], out[u]);
else rem(in[u], out[u]);
/* for(int i = 1; i <= n; i++)
cout << a[i] << ' ';
cout << "\n";*/
}
for(int i = 1; i <= q; i++){
int v; cin >> v;
int o = getlast(1, 1, n, 1, in[v], out[v]);
cout << a[o] << "\n";
}
return 0;
}
Compilation message
synchronization.cpp: In function 'int add(int, int)':
synchronization.cpp:66:1: warning: no return statement in function returning non-void [-Wreturn-type]
66 | }
| ^
synchronization.cpp: In function 'int rem(int, int)':
synchronization.cpp:73:1: warning: no return statement in function returning non-void [-Wreturn-type]
73 | }
| ^
synchronization.cpp: In function 'int main()':
synchronization.cpp:105:13: warning: unused variable 'v' [-Wunused-variable]
105 | int v = ed[x].s;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
16340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
97 ms |
32008 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
16352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
108 ms |
36176 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
16340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |