# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44631 | RayaBurong25_1 | Network (BOI15_net) | C++17 | 14 ms | 12132 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 <stdio.h>
#include <vector>
std::vector<int> AdjList[500005];
std::vector<int> Leaf;
int Root;
void dfs(int u, int pa)
{
if (pa == 0)
Root = u;
int i, v, s = AdjList[u].size();
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa)
{
dfs(v, u);
}
}
if (s == 1)
Leaf.push_back(u);
}
int main()
{
int N;
scanf("%d", &N);
int i, j, u, v;
for (i = 0; i < N - 1; i++)
{
scanf("%d %d", &u, &v);
AdjList[u].push_back(v);
AdjList[v].push_back(u);
}
if (AdjList[1].size() > 1)
dfs(1, 0);
else
dfs(AdjList[1][0], 0);
printf("%d\n", (Leaf.size() + 1)/2);
for (i = 0, j = Leaf.size() - 1; i < j; i++, j--)
printf("%d %d\n", Leaf[i], Leaf[j]);
if (i == j)
printf("%d %d\n", Leaf[i], Root);
}
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... |