제출 #520162

#제출 시각아이디문제언어결과실행 시간메모리
520162krit3379Network (BOI15_net)C++14
100 / 100
449 ms47556 KiB
#include<bits/stdc++.h> using namespace std; #define N 500005 vector<int> g[N],v; void dfs(int s,int f){ if(g[s].size()==1)v.push_back(s); for(auto x:g[s]){ if(x==f)continue; dfs(x,s); } } int main(){ int n,i,a,b,ans; scanf("%d",&n); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } dfs(1,0); printf("%d\n",ans=(v.size()+1)/2); for(i=0;i<ans;i++)printf("%d %d\n",v[i],(i+ans<v.size())?v[i+ans]:v[0]); return 0; }

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

net.cpp: In function 'int main()':
net.cpp:25:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(i=0;i<ans;i++)printf("%d %d\n",v[i],(i+ans<v.size())?v[i+ans]:v[0]);
      |                                              ~~~~~^~~~~~~~~
net.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
net.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...