Submission #876008

#TimeUsernameProblemLanguageResultExecution timeMemory
876008vjudge1Network (BOI15_net)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> links[n+1]; for(int i=0; i<n-1; i++){ int a,b; cin>>a>>b; links[a].push_back(b); links[b].push_back(a); } int last=0; int total=0; vector<pair<int,int>> ans; for(int i=1; i<=n; i++){ if(links[i].size()==1){ if(last==0){ last=i; } else{ total++; ans.push_back({last,i}); last=0; } } } if(last!=0){ total++; if(last==1){ ans.push_back({last,2}); } else{ ans.push_back({last,1}); } } cout<<total<<endl; for(int i=0; i<ans.size(); i++){ cout<<ans[i].first<<' '<<ans[i].second<<endl; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=0; i<ans.size(); i++){
      |               ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...