Submission #159745

#TimeUsernameProblemLanguageResultExecution timeMemory
159745geon040702트리 (KOI16_treeM)C++14
100 / 100
181 ms14968 KiB
#include <bits/stdc++.h> using namespace std; int Find_Root(int Node); int Tree[200010]; int Parent[200010]; int Input[400010][3]; int answer[400010]; int main(void) { int Node, Ques, ans_cnt, i; scanf("%d %d", &Node, &Ques); ans_cnt = Ques; Tree[1] = Parent[1] = 1; for(i=2;i<=Node;i++) { Tree[i] = i; scanf("%d", &Parent[i]); } for(i=1;i<=Node+Ques-1;i++) { scanf("%d %d", &Input[i][0], &Input[i][1]); if(Input[i][0] == 1) { scanf("%d", &Input[i][2]); } } for(i=Node+Ques-1;i>=1;i--) { if(ans_cnt == 0) { break; } if(Input[i][0] == 0) { Tree[Input[i][1]] = Parent[Input[i][1]]; } else { if(Find_Root(Input[i][1]) == Find_Root(Input[i][2])) { answer[ans_cnt] = 1; } ans_cnt--; } } for(i=1;i<=Ques;i++) { printf("%s\n", answer[i] ? "YES" : "NO"); } return 0; } int Find_Root(int Node) { if(Tree[Node] != Node) { Tree[Node] = Find_Root(Tree[Node]); } return Tree[Node]; }

Compilation message (stderr)

tree.cpp: In function 'int main()':
tree.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &Node, &Ques);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &Parent[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~
tree.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &Input[i][0], &Input[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:27:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &Input[i][2]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...