# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51032 | SpaimaCarpatilor | Network (BOI15_net) | C++17 | 687 ms | 153292 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<cstdio>
#include<vector>
using namespace std;
int N, nr, rad, cod[500009];
vector < int > v[500009];
void dfs (int nod, int tata)
{
if (v[nod].size () == 1) cod[++nr] = nod;
for (vector < int > :: iterator it = v[nod].begin (); it != v[nod].end (); it ++)
if (*it != tata)
dfs (*it, nod);
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d", &N);
for (int i=1; i<N; i++)
{
int x, y;
scanf ("%d %d", &x, &y);
v[x].push_back (y), v[y].push_back (x);
}
for (int i=1; i<=N; i++)
if (v[i].size () >= 2) rad = i;
dfs (rad, -1);
printf ("%d\n", nr / 2 + nr % 2);
for (int i=1; i + nr / 2 <= nr; i++)
printf ("%d %d\n", cod[i], cod[i + nr / 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... |