# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
630401 | MasterTaster | Network (BOI15_net) | C++14 | 4 ms | 4992 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 pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 200010
using namespace std;
int n;
vector<int> g[MAXN], listovi;
bool bio[MAXN];
void dfs(int u)
{
bio[u]=true;
if (g[u].size()==1) listovi.pb(u);
for (auto v:g[u]) if (!bio[v]) dfs(v);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
if (n==1) { cout<<1<<endl<<1<<" "<<1; exit(0); }
if (n==2) { cout<<1<<endl<<1<<" "<<2; exit(0); }
for (int i=1; i<n; i++)
{
int u, v; cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
for (int i=1; i<n; i++) if (g[i].size()!=1) { dfs(i); break; }
//for (int i=0; i<listovi.size(); i++) cout<<listovi[i]<<" ";
cout<<(listovi.size()+1)/2<<endl;
for (int i=0; i<listovi.size()/2; i++)
{
cout<<listovi[i]<<" "<<listovi[i+listovi.size()/2]<<endl;
}
if (listovi.size()%2) cout<<listovi[listovi.size()-2]<<" "<<listovi[listovi.size()-1];
}
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... |