Submission #226273

#TimeUsernameProblemLanguageResultExecution timeMemory
226273MKopchevNetwork (BOI15_net)C++14
100 / 100
519 ms45300 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=5e5+42; int n; vector<int> adj[nmax]; vector<int> leaves; void dfs(int node,int par) { if(adj[node].size()==1)leaves.push_back(node); for(auto k:adj[node]) if(k!=par)dfs(k,node); } int main() { scanf("%i",&n); int u,v; for(int i=1;i<n;i++) { scanf("%i%i",&u,&v); adj[u].push_back(v); adj[v].push_back(u); } for(int i=1;i<=n;i++) if(adj[i].size()>=2) { dfs(i,0); break; } int output=(leaves.size()+1)/2; printf("%i\n",output); int step=leaves.size()-output; for(int i=0;i<output;i++) { printf("%i %i\n",leaves[i],leaves[i+step]); } return 0; }

Compilation message (stderr)

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