Submission #56864

#TimeUsernameProblemLanguageResultExecution timeMemory
56864red1108트리 (KOI16_treeM)C++17
100 / 100
237 ms65420 KiB
#include <stdio.h> #include <stack> using namespace std; stack<bool> ans; int bumo[200010], input[500010][3], par[200010]; int n, q; int pfind(int x) { if(par[x]==x) return x; return par[x]=pfind(par[x]); } void uni(int a, int b) { par[pfind(a)]=pfind(b); } int main() { int i, a, b; scanf("%d %d", &n, &q); par[1]=1; for(i=2;i<=n;i++) { par[i]=i; scanf("%d", &bumo[i]); } for(i=1;i<=q+n-1;i++) { scanf("%d %d", &input[i][0], &input[i][1]); if(input[i][0]==1) { scanf("%d", &input[i][2]); } } for(i=q+n-1;i>=1;i--) { if(input[i][0]==1) { if(pfind(input[i][1])==pfind(input[i][2])) { ans.push(1); } else ans.push(0); } else { uni(input[i][1],bumo[input[i][1]]); } } while(!ans.empty()) { printf("%s\n",ans.top()==1?"YES":"NO"); ans.pop(); } }

Compilation message (stderr)

tree.cpp: In function 'int main()':
tree.cpp:18:12: warning: unused variable 'a' [-Wunused-variable]
     int i, a, b;
            ^
tree.cpp:18:15: warning: unused variable 'b' [-Wunused-variable]
     int i, a, b;
               ^
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", &bumo[i]);
         ~~~~~^~~~~~~~~~~~~~~~
tree.cpp:28: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:31: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...