| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 93779 | kjain_1810 | Network (BOI15_net) | C++11 | 7 ms | 5240 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 f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N=1e5+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
ll n;
vector<ll>adj[N], leaf, nonleaf;
void dfs(ll u, ll p)
{
if(adj[u].size()==1)
leaf.pb(u);
else
nonleaf.pb(u);
for(auto v:adj[u])
if(v!=p)
dfs(v, u);
}
int main()
{
inlld(n);
for(ll a=1; a<n; a++)
{
ll u, v;
inlld2(u, v);
adj[u].pb(v);
adj[v].pb(u);
}
for(ll a=1; a<=n; a++)
if(adj[a].size()>1)
{
dfs(a, 0);
break;
}
ll ans=((int)leaf.size()+1)/2;
printf("%lld\n", ans);
for(ll a=0; a*2+1<leaf.size(); a++)
printf("%lld %lld\n", leaf[a], leaf[a+(leaf.size()+1)/2]);
if(leaf.size()%2==1)
printf("%lld %lld\n", leaf[leaf.size()/2], leaf[0]);
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... | ||||
