Submission #151239

#TimeUsernameProblemLanguageResultExecution timeMemory
151239cfalasNetwork (BOI15_net)C++14
100 / 100
1455 ms53260 KiB
#include<bits/stdc++.h> using namespace std; vector<vector<int> > adj; vector<int> ans; void dfs(int s, int p=-1){ if(adj[s].size()==1){ ans.push_back(s); } for(auto v : adj[s] ){ if(v!=p) dfs(v, s); } } int main(){ int n; adj.assign(1000000, vector<int>()); cin>>n; for(int i=0;i<n-1;i++){ int b, c; cin>>b>>c; adj[b].push_back(c); adj[c].push_back(b); } dfs(1); cout<<(ans.size()+1)/2<<endl; for(int i=0;i<(ans.size()+1)/2;i++){ cout<<ans[i]<<" "<<ans[(i+(ans.size()+1)/2)%ans.size()]<<endl; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<(ans.size()+1)/2;i++){
              ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...