#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 1e5 + 2;
vector<int> g[N];
int in[N], out[N], par[N][17], tsz;
int u[N], v[N], ans[N], sync[N];
bool active[N];
void Dfs(int s, int e) {
in[s] = ++tsz;
par[s][0] = e;
for (int i = 1; i < 17; i++) par[s][i] = par[par[s][i - 1]][i - 1];
for (auto u : g[s]) {
if (u == e) continue;
Dfs(u, s);
}
}
int bit[2 * N];
void Add(int x, int v) {
for (; x < 2 * N; x += x & (-x)) bit[x] += v;
}
int Get(int x) {
int ans = 0;
for (; x > 0; x -= x & (-x)) ans += bit[x];
return ans;
}
int Getroot(int x) {
for (int i = 16; i >= 0; i--) {
if (par[x][i] && Get(in[par[x][i]]) == Get(in[x])) x = par[x][i];
}
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
cin >> u[i] >> v[i];
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
Dfs(1, 0);
for (int i = 1; i <= n; i++) {
ans[i] = 1;
Add(in[i], 1);
}
for (int i = 1; i < n; i++) if (in[u[i]] > in[v[i]]) swap(u[i], v[i]);
while (m--) {
int i; cin >> i;
if (active[i] == 0) {
int k = Getroot(u[i]);
ans[Getroot(u[i])] += ans[v[i]] - sync[v[i]];
Add(in[v[i]], -1);;
}
else {
ans[v[i]] = sync[v[i]] = ans[Getroot(u[i])];
Add(in[v[i]], 1);;
}
active[i] = 1 - active[i];
}
while (q--) {
int x; cin >> x;
cout << ans[Getroot(x)] << en;
}
return 0;
}
Compilation message
synchronization.cpp: In function 'int main()':
synchronization.cpp:60:17: warning: unused variable 'k' [-Wunused-variable]
60 | int k = Getroot(u[i]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2724 KB |
Output is correct |
3 |
Correct |
2 ms |
2676 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
19136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2676 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2812 KB |
Output is correct |
7 |
Correct |
17 ms |
4660 KB |
Output is correct |
8 |
Correct |
269 ms |
22656 KB |
Output is correct |
9 |
Correct |
270 ms |
22652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
22704 KB |
Output is correct |
2 |
Correct |
149 ms |
21988 KB |
Output is correct |
3 |
Correct |
149 ms |
22196 KB |
Output is correct |
4 |
Correct |
158 ms |
22264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |