Submission #84050

#TimeUsernameProblemLanguageResultExecution timeMemory
84050tjdgus4384트리 (KOI16_treeM)C++14
43 / 100
2061 ms33676 KiB
#include<cstdio> #include<vector> using namespace std; int pa[200001], g[200001]; vector<int> v[200001]; void spread(int x, int y) { for(int i = 0;i < v[x].size();i++) { if(g[v[x][i]] == g[x]) spread(v[x][i], y); } g[x] = y; } 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]); v[pa[i]].push_back(i); g[i] = 1; } for(int i = 1;i < n + q;i++) { scanf("%d", &x); if(!x) { scanf("%d", &b); spread(b, b); } else { scanf("%d %d", &c, &d); if(g[c] == g[d]) printf("YES\n"); else printf("NO\n"); } } return 0; }

Compilation message (stderr)

tree.cpp: In function 'void spread(int, int)':
tree.cpp:9:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < v[x].size();i++)
                   ~~^~~~~~~~~~~~~
tree.cpp: In function 'int main()':
tree.cpp:19: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:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &pa[i]);
         ~~~~~^~~~~~~~~~~~~~
tree.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tree.cpp:33:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b);
             ~~~~~^~~~~~~~~~
tree.cpp:38: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...