# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119651 | Bruteforceman | Synchronization (JOI13_synchronization) | C++11 | 8063 ms | 33248 KiB |
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;
int l[100010], r[100010];
int n;
int par[100010];
vector <int> g[100010];
vector <int> t[500010];
int cur;
bool vis[100010];
int node[100010];
int sub[500010];
void dfs(int x, int p) {
par[x] = p;
for(auto e : g[x]) {
int i = l[e] ^ r[e] ^ x;
if(e - p) {
dfs(i, e);
}
}
}
int root(int u) {
while(vis[par[u]]) {
u ^= l[par[u]] ^ r[par[u]];
}
return u;
}
int cnt;
void subtree(int x) {
if(sub[x] != -1) return ;
sub[x] = 1;
cnt += (x <= n);
for(auto i : t[x]) {
subtree(i);
}
}
int main(int argc, char const *argv[])
{
int m, qr;
scanf("%d %d %d", &n, &m, &qr);
for(int i = 1; i < n; i++) {
scanf("%d %d", l + i, r + i);
g[l[i]].push_back(i);
g[r[i]].push_back(i);
}
dfs(1, 0);
cur = n;
for(int i = 1; i <= n; i++) {
node[i] = i;
}
for(int i = 1; i <= m; i++) {
int e;
scanf("%d", &e);
int u;
if(par[l[e]] == e) {
u = l[e];
} else {
u = r[e];
}
if(vis[e]) {
node[u] = node[root(u)];
vis[e] ^= 1;
} else {
vis[e] ^= 1;
int r = root(u);
int p = node[r];
int q = node[u];
node[r] = ++cur;
t[cur].push_back(p);
t[cur].push_back(q);
// cout << cur << ' ' << p << endl;
// cout << cur << ' ' << q << endl;
}
}
for(int i = 1; i <= qr; i++) {
int u;
scanf("%d", &u);
cnt = 0;
memset(sub, -1, sizeof sub);
subtree(node[root(u)]);
printf("%d\n", cnt);
}
return 0;
}
Compilation message (stderr)
# | 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... |