Submission #127034

#TimeUsernameProblemLanguageResultExecution timeMemory
127034TadijaSebezNetwork (BOI15_net)C++11
100 / 100
573 ms47844 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=500050; vector<int> E[N],leaf; void DFS(int u, int p) { if(E[u].size()==1) leaf.pb(u); for(int v:E[u]) if(v!=p) DFS(v,u); } int main() { int n,u,v; scanf("%i",&n); for(int i=1;i<n;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u); DFS(1,0); int sz=leaf.size()+1>>1,add=leaf.size()>>1; printf("%i\n",sz); for(int i=0;i<sz;i++) printf("%i %i\n",leaf[i],leaf[i+add]); return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:17:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int sz=leaf.size()+1>>1,add=leaf.size()>>1;
         ~~~~~~~~~~~^~
net.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
net.cpp:15:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<n;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u);
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...