제출 #106891

#제출 시각아이디문제언어결과실행 시간메모리
106891PajarajaNetwork (BOI15_net)C++17
100 / 100
735 ms47688 KiB
#include <bits/stdc++.h> using namespace std; vector<int> g[500007]; int k[500007],cnt; void dfs(int s,int f) { if(g[s].size()==1) {k[cnt++]=s; return;} for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s); } int main() { int n,v1,v2,l=0; scanf("%d",&n); for(int i=0;i<n-1;i++) { scanf("%d%d",&v1,&v2); g[v1].push_back(v2); g[v2].push_back(v1); } for(int i=1;i<=n;i++) if(g[i].size()==1) l++; printf("%d\n",(l+1)/2); for(int i=1;i<=n;i++) if(g[i].size()>1) { dfs(i,0); for(int j=0;j<l/2;j++) printf("%d %d\n",k[j],k[j+(l+1)/2]); if(l%2==1) printf("%d %d",i,k[l/2]); return 0; } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'void dfs(int, int)':
net.cpp:8:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s);
                 ~^~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
net.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v1,&v2);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...