Submission #84060

#TimeUsernameProblemLanguageResultExecution timeMemory
84060tjdgus4384트리 (KOI16_treeM)C++14
100 / 100
209 ms36800 KiB
#include<cstdio> #include<algorithm> #include<string> #include<iostream> using namespace std; int pa[200001], query[500001][3]; int g[200001], s[200001]; string ans[200001]; int find(int a) { if(pa[a] == a) return a; else return pa[a] = find(pa[a]); } void merge(int x, int y) { pa[find(x)] = find(y); } int main() { int n, q; scanf("%d %d", &n, &q); pa[1] = 1; for(int i = 2;i <= n;i++) { scanf("%d", &g[i]); pa[i] = i; } for(int i = 1;i < n + q;i++) { scanf("%d", &query[i][0]); if(query[i][0]) scanf("%d %d", &query[i][1], &query[i][2]); else scanf("%d", &query[i][1]); } int t = 0; for(int i = n + q - 1;i > 0;i--) { if(!query[i][0]) merge(query[i][1], g[query[i][1]]); else { if(find(query[i][1]) == find(query[i][2])) ans[t++] = "YES"; else ans[t++] = "NO"; } } for(int i = t - 1;i >= 0;i--) { cout << ans[i] << "\n"; } return 0; }

Compilation message (stderr)

tree.cpp: In function 'int main()':
tree.cpp:24: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:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &g[i]);
         ~~~~~^~~~~~~~~~~~~
tree.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &query[i][0]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
tree.cpp:34:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         if(query[i][0]) scanf("%d %d", &query[i][1], &query[i][2]);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:35:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         else scanf("%d", &query[i][1]);
              ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...