Submission #59637

#TimeUsernameProblemLanguageResultExecution timeMemory
59637IvanCNetwork (BOI15_net)C++17
100 / 100
754 ms153032 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5*1e5 + 10; vector<int> grafo[MAXN],folhas; int N; void dfs(int v,int p){ if(grafo[v].size() == 1) folhas.push_back(v); for(int u : grafo[v]) if(u != p) dfs(u,v); } int main(){ scanf("%d",&N); for(int i = 1;i<N;i++){ int u,v; scanf("%d %d",&u,&v); grafo[u].push_back(v); grafo[v].push_back(u); } dfs(1,-1); int ans = (folhas.size() + 1)/2; int delta = (folhas.size())/2; printf("%d\n",ans); for(int i = 0;i<ans;i++){ printf("%d %d\n",folhas[i],folhas[i + delta]); } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
net.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...