Submission #23205

#TimeUsernameProblemLanguageResultExecution timeMemory
23205iletavcioskiNetwork (BOI15_net)C++14
63 / 100
656 ms30820 KiB
#include<iostream> #include<vector> using namespace std; vector<vector<int> > v; int brojac=0; vector<int> toc; void dfs(int x,int prev) { for(int i=0;i<v[x].size();i++) if(v[x][i]!=prev) dfs(v[x][i],x); if(v[x].size()==1) toc.push_back(x); } int main() { int n; cin>>n; vector<int> vec; v.insert(v.begin(),n+1,vec); if(n==1) { cout<<0<<endl; return 0; } for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; a--; b--; v[a].push_back(b); v[b].push_back(a); } brojac=0; for(int i=0;i<n;i++) { if(v[i].size()>1){ dfs(i,-1); break;} } cout<<(int)(toc.size()+1)/2<<endl; for(int i=0;i<(toc.size()+1)/2;i++) { cout<<toc[i]+1<<" "<<toc[i+(toc.size())/2]+1<<endl; } return 0; }

Compilation message (stderr)

net.cpp: In function 'void dfs(int, int)':
net.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v[x].size();i++)
               ^
net.cpp: In function 'int main()':
net.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<(toc.size()+1)/2;i++)
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...