//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.second == p) {
continue;
}
dfs(to.second, v);
}
}
vector<int>ans[100005];
int GetPr(int x) {
return pr[x] == x ? x : GetPr(pr[x]);
}
inline void MergeAns(int x, int 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());
ans[x] = ans[y];
}
inline void Split(int x, int y) {
if(depth[x] < depth[y]) {
swap(x, y);
}
pr[x] = x;
MergeAns(x, y);
}
inline void Merge(int x, int y) {
if(depth[x] < depth[y]) {
swap(x, y);
}
pr[x] = y;
MergeAns(x, y);
}
int x[100005], y[100005];
int d[100005], c[100005];
inline int get(int v) {
/* for(auto &to : ans[v]) {
debug("%d ", to);
}
debug("\n\n");*/
return (int)ans[v].size();
}
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) {
//int d;
//scanf("%d\n", &d);
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 <= q; ++i) {
//int c;
//scanf("%d\n", &c);
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:104: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:106: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:128:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d\n", c + i);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
9 ms |
8184 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
912 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
8184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
377 ms |
36728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8188 KB |
Output is correct |
2 |
Correct |
8 ms |
8184 KB |
Output is correct |
3 |
Incorrect |
8 ms |
8184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |