Submission #23207

#TimeUsernameProblemLanguageResultExecution timeMemory
23207iletavcioskiNetwork (BOI15_net)C++14
100 / 100
659 ms42516 KiB
#include<iostream> #include<vector> #include<cstdio> 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; scanf("%d %d",&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;} } printf("%d\n",(toc.size()+1)/2); for(int i=0;i<(toc.size()+1)/2;i++) { printf("%d %d\n",toc[i]+1,toc[i+(toc.size())/2]+1); } 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:44:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",(toc.size()+1)/2);
                                ^
net.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<(toc.size()+1)/2;i++)
               ^
net.cpp:31:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a,&b);
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...