Submission #84045

#TimeUsernameProblemLanguageResultExecution timeMemory
84045tjdgus4384트리 (KOI16_treeM)C++14
43 / 100
2048 ms57312 KiB
#include<cstdio> int pa[200001], g[200001]; int find(int x) { if(g[x] == x) return x; else return g[x] = find(pa[x]); } int main() { int n, q, x, b, c, d; scanf("%d %d", &n, &q); pa[1] = 1; g[1] = 1; for(int i = 2;i <= n;i++) { scanf("%d", &pa[i]); g[i] = 1; } for(int i = 1;i < n + q;i++) { scanf("%d", &x); if(!x) { scanf("%d", &b); g[b] = b; } else { scanf("%d %d", &c, &d); if(find(c) == find(d)) printf("YES\n"); else printf("NO\n"); } } return 0; }

Compilation message (stderr)

tree.cpp: In function 'int main()':
tree.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
tree.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &pa[i]);
         ~~~~~^~~~~~~~~~~~~~
tree.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tree.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b);
             ~~~~~^~~~~~~~~~
tree.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &c, &d);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...