Submission #23204

#TimeUsernameProblemLanguageResultExecution timeMemory
23204iletavcioskiNetwork (BOI15_net)C++14
0 / 100
0 ms2024 KiB
#include<iostream> #include<vector> using namespace std; vector<vector<int> > v; int brojac=0; vector<int> toc; void dfs(int x,int prev) { if(v[x].size()==1) toc.push_back(x); for(int i=0;i<v[x].size();i++) if(v[x][i]!=prev) dfs(v[x][i],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; dfs(0,-1); if(toc.size()%2) { toc.push_back(toc[0]); } cout<<(int)(toc.size())/2<<endl; for(int i=0;i<toc.size()-1;i+=2) { cout<<toc[i]+1<<" "<<toc[i+1]+1<<endl; } return 0; }

Compilation message (stderr)

net.cpp: In function 'void dfs(int, int)':
net.cpp:11: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:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<toc.size()-1;i+=2)
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...