This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e5;
int n, m, q, eu[mxN], ev[mxN], p[mxN], edge[mxN], last[mxN], ans[mxN];
vector<int> adj[mxN];
bool active[mxN];
void dfs(int u=0) {
for (int i : adj[u]) {
int v=eu[i]^ev[i]^u;
if (v!=p[u]) {
p[v]=u;
edge[i]=v;
dfs(v);
}
}
}
int get_head(int u) {
for (; u&&active[u]; u=p[u]);
return u;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int i=1; i<n; ++i) {
cin >> eu[i] >> ev[i], --eu[i], --ev[i];
adj[eu[i]].push_back(i);
adj[ev[i]].push_back(i);
}
dfs();
fill(ans, ans+n, 1);
while(m--) {
int u;
cin >> u;
u=edge[u];
//cout << "activatting " << u << endl;
if (!active[u]) { // activate edge between u-p[u]
int v=get_head(p[u]);
ans[v]+=ans[u]-last[u];
} else {
ans[u]=ans[get_head(u)];
last[u]=ans[u];
}
active[u]^=1;
}
while(q--) {
int u;
cin >> u, --u;
cout << ans[get_head(u)] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |