# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305461 | shahriarkhan | Network (BOI15_net) | C++14 | 11 ms | 12032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
const int siz = 5e5 + 69 ;
vector<int> adj[siz] , ar ;
int deg[siz] ;
void dfs(int s , int p)
{
for(int t : adj[s])
{
if(t==p) continue ;
dfs(t,s) ;
}
if(deg[s]==1) ar.push_back(s) ;
}
int main()
{
int n ;
scanf("%d",&n) ;
for(int i = 1 ; i < n ; ++i)
{
int u , v ;
scanf("%d%d",&u,&v) ;
adj[u].push_back(v) ;
adj[v].push_back(u) ;
++deg[u] , ++deg[v] ;
}
int root = 0 ;
for(int i = 1 ; i <= n ; ++i)
{
if(deg[i]!=1)
{
root = i ;
break ;
}
}
dfs(root,0) ;
int six = ar.size() ;
printf("%d\n",(six+1)/2) ;
if(six%2)
{
ar.push_back(ar[0]) ;
++six ;
}
else swap(ar[0],ar[six-2]) ;
for(int i = 0 ; i < six ; i += 2)
{
printf("%d %d\n",ar[i],ar[i+1]) ;
}
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |