#include <bits/stdc++.h>
using namespace std;
int par[100005][17], bit[100005], ok[100005], in[100005], out[100005], a[100005], b[100005], n, m, q, t;
vector<pair<int, int> > edge;
vector<int> adj[100005];
void update(int x, int y)
{
for (int i=x; i<=n; i+=i&(-i))
bit[i]+=y;
}
int query(int x)
{
int ans=0;
for (int i=x; i; i-=i&(-i))
ans+=bit[i];
return ans;
}
int findPar(int u)
{
for (int i=16; i>=0; i--)
if (query(in[u])==query(in[par[u][i]]))
u=par[u][i];
return u;
}
void dfs(int u, int p)
{
par[u][0]=p;
for (int i=1; i<=16; i++)
par[u][i]=par[par[u][i-1]][i-1];
in[u]=++t;
for (int v:adj[u])
if (v!=p)
dfs(v, u);
out[u]=t+1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for (int i=1; i<n; i++)
{
int u, v;
cin >> u >> v;
edge.push_back({u, v});
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 1);
for (int i=1; i<=n; i++)
{
update(in[i], 1);
update(out[i], -1);
a[i]=1;
}
for (int i=1; i<=m; i++)
{
int x, u, v, w;
cin >> x;
u=edge[x-1].first;
v=edge[x-1].second;
if (par[u][0]==v)
swap(u, v);
w=findPar(u);
if (ok[x])
{
a[v]=b[v]=a[w];
update(in[v], 1);
update(out[v], -1);
}
else
{
a[w]+=a[v]-b[v];
update(in[v], -1);
update(out[v], 1);
}
ok[x]^=1;
}
for (int i=1; i<=q; i++)
{
int x;
cin >> x;
cout << a[findPar(x)] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
12 ms |
4052 KB |
Output is correct |
8 |
Correct |
13 ms |
3924 KB |
Output is correct |
9 |
Correct |
13 ms |
3964 KB |
Output is correct |
10 |
Correct |
167 ms |
15676 KB |
Output is correct |
11 |
Correct |
169 ms |
15680 KB |
Output is correct |
12 |
Correct |
176 ms |
20272 KB |
Output is correct |
13 |
Correct |
90 ms |
15932 KB |
Output is correct |
14 |
Correct |
117 ms |
15264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
17752 KB |
Output is correct |
2 |
Correct |
83 ms |
17652 KB |
Output is correct |
3 |
Correct |
87 ms |
19856 KB |
Output is correct |
4 |
Correct |
84 ms |
19932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2772 KB |
Output is correct |
7 |
Correct |
17 ms |
4492 KB |
Output is correct |
8 |
Correct |
234 ms |
20484 KB |
Output is correct |
9 |
Correct |
225 ms |
20408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
20376 KB |
Output is correct |
2 |
Correct |
159 ms |
20544 KB |
Output is correct |
3 |
Correct |
141 ms |
20468 KB |
Output is correct |
4 |
Correct |
135 ms |
20528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2772 KB |
Output is correct |
6 |
Correct |
20 ms |
4180 KB |
Output is correct |
7 |
Correct |
220 ms |
15928 KB |
Output is correct |
8 |
Correct |
219 ms |
20408 KB |
Output is correct |
9 |
Correct |
117 ms |
16484 KB |
Output is correct |
10 |
Correct |
153 ms |
15952 KB |
Output is correct |
11 |
Correct |
110 ms |
18400 KB |
Output is correct |
12 |
Correct |
110 ms |
18452 KB |
Output is correct |
13 |
Correct |
141 ms |
20516 KB |
Output is correct |