# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503958 | goodluck2020 | Network (BOI15_net) | C++14 | 433 ms | 47816 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 task "BOI15_net"
#define sz(X) ((int)X.size())
using namespace std;
const int N = 5e5 + 5;
int n;
vector < int > adj[N], Leaf;
vector < pair < int , int > > res;
void DFS(int u, int par)
{
if(sz(adj[u]) == 1) Leaf.push_back(u);
for(int v : adj[u])
if(v != par) DFS(v, u);
}
int main()
{
if(fopen(task ".inp","r"))
{
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
DFS(1, 0);
for(int i = 0; i < (sz(Leaf) + 1)/2; i++)
res.push_back({Leaf[i], Leaf[i + sz(Leaf)/2]});
cout << sz(res) << '\n';
for(auto it : res) cout << it.first << " " << it.second << '\n';
}
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... |