# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43764 | PowerOfNinjaGo | Network (BOI15_net) | C++14 | 665 ms | 152844 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.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 5e5+5;
vi adj[maxn];
vi leaf;
void dfs(int u, int p)
{
bool found = 0;
for(auto v : adj[u])
{
if(v == p) continue;
dfs(v, u);
found = 1;
}
if(!found) leaf.pb(u);
}
int main()
{
//#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
int n; scanf("%d", &n);
for(int i = 0; i< n-1; i++)
{
int u, v; scanf("%d %d", &u, &v);
adj[u].pb(v); adj[v].pb(u);
}
int s = 1;
for(int i = 1; i<= n; i++) if(adj[i].size()> 1) s = i;
dfs(s, 0);
printf("%d\n", (leaf.size()+1)/2);
int mid = (leaf.size()+1)/2;
for(int i = 0; i< mid; i++)
{
printf("%d %d\n", leaf[i], leaf[min((int) leaf.size()-1, mid+i)]);
}
}
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... |