제출 #51613

#제출 시각아이디문제언어결과실행 시간메모리
51613okaybody10Network (BOI15_net)C++98
100 / 100
673 ms155376 KiB
#include <bits/stdc++.h> using namespace std; vector<int> v[600005],ans; void dfs(int e,int s) { if(v[e].size()==1) { ans.push_back(e); return; } int sz=v[e].size(); for(int i=0;i<sz;i++) { if(v[e][i]==s) continue; dfs(v[e][i],e); } } int main() { int n; scanf("%d",&n); for(int i=0;i<n-1;i++) { int x,y; scanf("%d %d",&x,&y); v[x].push_back(y); v[y].push_back(x); } int firstdfs; for(int i=1;i<=n;i++) if(v[i].size()>=2) { firstdfs=i; break;} dfs(firstdfs,-1); int sz=ans.size(); printf("%d\n",sz/2+sz%2); for(int i=0;i+sz/2<sz;i++) printf("%d %d\n",ans[i],ans[i+sz/2]); return 0; }

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

net.cpp: In function 'int main()':
net.cpp:16:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d",&n);
            ~~~~~^~~~~~~~~
net.cpp:19:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int x,y; scanf("%d %d",&x,&y);
                  ~~~~~^~~~~~~~~~~~~~~
net.cpp:25:8: warning: 'firstdfs' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dfs(firstdfs,-1);
     ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...