# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134329 | Kastanda | Network (BOI15_net) | C++11 | 611 ms | 57800 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.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
int n;
vector < int > V, Adj[N];
void DFS(int v, int p)
{
for (int &u : Adj[v])
if (u != p)
DFS(u, v);
if (Adj[v].size() == 1)
V.push_back(v);
}
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 root = 1;
for (int i = 1; i <= n; i ++)
if (Adj[i].size() > 1)
root = i;
DFS(root, 0);
printf("%d\n", (int)(V.size() + 1) / 2);
for (int i = 0; i < (V.size() + 1) / 2; i ++)
printf("%d %d\n", V[i], V[i + (int)V.size() / 2]);
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... |