# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108712 | ckodser | Network (BOI15_net) | C++14 | 722 ms | 53240 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 x first
#define y second
using namespace std;
const int N = 500005;
int n, ts, st[N];;
vector < int > Adj[N];
void DFS(int v, int p)
{
st[v] = ts ++;
for (int &u : Adj[v])
if (u != p)
DFS(u, v);
}
bool CMP(int i, int j)
{
return (st[i] < st[j]);
}
int main()
{
scanf("%d", &n);
for (int i = 1; i < n; i++)
{
int v, u;
scanf("%d%d", &v, &u);
Adj[v].push_back(u);
Adj[u].push_back(v);
}
int id = 1;
for (int i = 1; i <= n; i++)
if (Adj[i].size() > 1)
id = i;
DFS(id, 0);
vector < int > vec;
for (int i = 1; i <= n; i++)
if ((int)Adj[i].size() == 1)
vec.push_back(i);
sort(vec.begin(), vec.end(), CMP);
int len = (int)vec.size() >> 1;
printf("%d\n", (int)vec.size() - len);
for (int i = 0; i < (int)vec.size() - len; i++)
printf("%d %d\n", vec[i], vec[i + len]);
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... |