//In the name of God
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
const char nxtl = '\n';
const int inf = (int)2e9 + 228;
const double eps = (double)1e-7;
const int mod = (int)1e9 + 7;
template<typename T>
inline bool updmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template<typename T>
inline bool updmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>
using ordered_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;
int pr[100005], depth[100005];
unordered_map<int, bool>have[100005];
void dfs(int v, int p) {
depth[v] = depth[p] + 1;
for(auto &to : have[v]) {
if(to.first == p) {
continue;
}
dfs(to.first, v);
}
}
int GetPr(int x) {
return pr[x] == x ? x : GetPr(pr[x]);
}
vector<int>ans[100005];
inline void DEBUG(int v) {
for(auto &to : ans[v]) {
debug("%d ", to);
}
debug("\n\n");
}
inline void Split(int x, int y) {
if(depth[x] < depth[y]) {
swap(x, y);
}
pr[x] = x;
y = GetPr(y);
for(auto &to : ans[y]) {
ans[x].push_back(to);
}
sort(ans[x].begin(), ans[x].end());
ans[x].resize(unique(ans[x].begin(), ans[x].end()) - ans[x].begin());
}
inline void Merge(int x, int y) {
if(depth[x] < depth[y]) {
swap(x, y);
}
pr[x] = y;
y = GetPr(y);
for(auto &to : ans[x]) {
ans[y].push_back(to);
}
sort(ans[y].begin(), ans[y].end());
ans[y].resize(unique(ans[y].begin(), ans[y].end()) - ans[y].begin());
}
inline int get(int v) {
return (int)ans[v].size();
}
int x[100005], y[100005], d[200005], c[100005];
signed main() {
#ifdef LOCAL
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
// ios_base::sync_with_stdio(0);
// cin.tie(0);
unsigned int FOR;
asm("rdtsc" : "=A"(FOR));
srand(FOR);
int n, m, q;
scanf("%d %d %d\n", &n, &m, &q);
for(int i = 1; i < n; ++i) {
scanf("%d %d\n", x + i, y + i);
have[x[i]][y[i]] = have[y[i]][x[i]] = 0;
}
for(int i = 1; i <= n; ++i) {
pr[i] = i;
ans[i].push_back(i);
}
dfs(1, -1);
for(int i = 1; i <= m; ++i) {
scanf("%d\n", d + i);
if(have[x[d[i]]][y[d[i]]]) {
Split(x[d[i]], y[d[i]]);
} else {
Merge(x[d[i]], y[d[i]]);
}
have[x[d[i]]][y[d[i]]] = have[y[d[i]]][x[d[i]]] ^= 1;
}
for(int i = 1; i <= n; ++i) {
if(i == pr[i]) {
continue;
}
Split(i, pr[i]);
}
for(int i = 1; i <= q; ++i) {
scanf("%d\n", c + i);
printf("%d\n", get(c[i]));
}
return 0;
}
Compilation message
synchronization.cpp:2:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:20000000")
synchronization.cpp: In function 'int main()':
synchronization.cpp:106:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d\n", &n, &m, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d\n", x + i, y + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d\n", d + i);
~~~~~^~~~~~~~~~~~~~~
synchronization.cpp:132:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d\n", c + i);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
8 ms |
8184 KB |
Output is correct |
4 |
Correct |
8 ms |
8184 KB |
Output is correct |
5 |
Correct |
8 ms |
8156 KB |
Output is correct |
6 |
Correct |
11 ms |
8696 KB |
Output is correct |
7 |
Correct |
91 ms |
16892 KB |
Output is correct |
8 |
Correct |
73 ms |
14840 KB |
Output is correct |
9 |
Correct |
141 ms |
21424 KB |
Output is correct |
10 |
Correct |
2171 ms |
168572 KB |
Output is correct |
11 |
Correct |
1731 ms |
140288 KB |
Output is correct |
12 |
Correct |
396 ms |
33104 KB |
Output is correct |
13 |
Execution timed out |
8103 ms |
141884 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8006 ms |
25796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8156 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8208 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8312 KB |
Output is correct |
6 |
Correct |
10 ms |
8440 KB |
Output is correct |
7 |
Correct |
29 ms |
10616 KB |
Output is correct |
8 |
Correct |
332 ms |
34140 KB |
Output is correct |
9 |
Correct |
319 ms |
34040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
418 ms |
31328 KB |
Output is correct |
2 |
Runtime error |
1870 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8184 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
14 ms |
8824 KB |
Output is correct |
6 |
Correct |
113 ms |
18680 KB |
Output is correct |
7 |
Correct |
2105 ms |
170292 KB |
Output is correct |
8 |
Correct |
422 ms |
34168 KB |
Output is correct |
9 |
Execution timed out |
8023 ms |
133304 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |