// oooo
/*
har chi delet mikhad bebar ~
gitar o ba khodet nabar! ~
;Amoo_Hasan;
*/
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
#pragma GCC optimzie("Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endlefii
#define endl '\n'
constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, Log = 30;
struct node {
int cnt, lz;
node() {
cnt = lz = 0;
}
} x[N << 2];
int u[N], v[N], h[N], st[N], fn[N], par[N][Log], tim, n, m, q;
ll last[N], sum[N];
bool vis[N];
vector<int> vc, G[N];
void dfs(int x, int p = 0) {
par[x][0] = p;
for(int i = 1; i < Log; i++) par[x][i] = par[par[x][i - 1]][i - 1];
h[x] = h[p] + 1;
st[x] = tim++;
for(auto &i : G[x]) {
if(i == p) continue;
dfs(i, x);
}
fn[x] = tim;
}
void put(int l, int r, int v) {
if(x[v].lz == 0) return;
x[2 * v].cnt += x[v].lz, x[2 * v].lz += x[v].lz;
x[2 * v + 1].cnt += x[v].lz, x[2 * v + 1].lz += x[v].lz;
x[v].lz = 0;
}
void change(int l, int r, int s, int e, int val, int v) {
if(r <= s || l >= e) return;
if(l >= s && r <= e) {
x[v].cnt += val;
x[v].lz += val;
return;
}
put(l, r, v);
int mid = (l + r) >> 1;
change(l, mid, s, e, val, 2 * v), change(mid, r, s, e, val, 2 * v + 1);
}
int get(int l, int r, int ind, int v) {
if(r - l < 2) return x[v].cnt;
put(l, r, v);
int mid = (l + r) >> 1;
if(ind < mid) return get(l, mid, ind, 2 * v);
return get(mid, r, ind, 2 * v + 1);
}
int get_par(int x) {
for(int i = Log - 1; i >= 0; i--) {
int val = get(0, n, st[par[x][i]], 1);
int val2 = get(0, n, st[x], 1);
if(val2 == val + (h[x] - h[par[x][i]])) x = par[x][i];
}
return x;
}
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
cin >>n >>m >>q;
for(int i = 1; i <= n - 1; i++) {
cin >>u[i] >>v[i];
G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
}
dfs(1);
for(int i = 1; i <= n - 1; i++) {
if(h[h[i]] > h[v[i]]) swap(u[i], v[i]);
}
for(int i = 1; i <= n; i++) sum[i] = 1;
while(m--) {
int ind; cin >>ind;
int ui = u[ind], vi = v[ind];
int pu = get_par(ui), pv = get_par(vi);
if(!vis[ind]) {
vis[ind] = 1;
int bac = sum[pu] + sum[pv] - last[ind];
change(0, n, st[vi], fn[vi], 1, 1);
pu = get_par(ui);
sum[pu] = bac;
}
else {
vis[ind] = 0;
last[ind] = sum[pu];
change(0, n, st[vi], fn[vi], -1, 1);
pu = get_par(ui), pv = get_par(vi);
sum[pu] = last[ind], sum[pv] = last[ind];
}
}
while(q--) {
int ind; cin >>ind;
int p = get_par(ind);
cout<<sum[p] <<endl;
}
return 0;
}
Compilation message
synchronization.cpp:11: warning: ignoring '#pragma GCC optimzie' [-Wunknown-pragmas]
11 | #pragma GCC optimzie("Ofast")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
55112 KB |
Output is correct |
2 |
Correct |
27 ms |
55116 KB |
Output is correct |
3 |
Correct |
32 ms |
55120 KB |
Output is correct |
4 |
Correct |
27 ms |
55108 KB |
Output is correct |
5 |
Incorrect |
27 ms |
55132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2231 ms |
77696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
55124 KB |
Output is correct |
2 |
Correct |
26 ms |
55092 KB |
Output is correct |
3 |
Correct |
27 ms |
55116 KB |
Output is correct |
4 |
Correct |
27 ms |
55236 KB |
Output is correct |
5 |
Correct |
30 ms |
55172 KB |
Output is correct |
6 |
Correct |
44 ms |
55404 KB |
Output is correct |
7 |
Correct |
287 ms |
57844 KB |
Output is correct |
8 |
Correct |
3591 ms |
81388 KB |
Output is correct |
9 |
Correct |
3679 ms |
81524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3638 ms |
81552 KB |
Output is correct |
2 |
Correct |
1802 ms |
80400 KB |
Output is correct |
3 |
Correct |
1758 ms |
80540 KB |
Output is correct |
4 |
Correct |
1779 ms |
80596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
55116 KB |
Output is correct |
2 |
Incorrect |
26 ms |
55120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |