# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476091 | ZaZo_ | Network (BOI15_net) | C++14 | 1 ms | 1484 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>
#define HID ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define all(v) v.begin(),v.end()
const int N = 50005 , INF = 1e15 , MOD=1000000006;
using namespace std;
int n ;
vector<int>edges[N];
vector<int>leaves;
void dfs(int node , int par)
{
if(edges[node].size()==1) leaves.push_back(node);
for(auto x : edges[node])
if(x!=par)
dfs(x,node);
}
int32_t main() {
HID
cin>>n;
for(int i = 0 ; i < n-1 ; i++)
{
int u , v;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
}
dfs(1,-1);
cout<<(leaves.size()+1)/2<<endl;
if(leaves.size()%2==0)
{
for(int i = 0 ; i < leaves.size()/2 ; i++)
cout<<leaves[i]<<" "<<leaves[leaves.size()/2+i]<<endl;
}
else
{
for(int i = 0 ; i < leaves.size()/2 ; i++)
{
if(i==leaves.size()-1) break;
cout<<leaves[i]<<" "<<leaves[leaves.size()/2+i]<<endl;
}
cout<<leaves[leaves.size()/2]<<" ";
for(int i = 1 ; i <= n ; i++)
{
if(i!=leaves.back()&&i!=edges[leaves.back()][0])
{
cout<<i<<endl;
break;
}
}
}
}
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... |