# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71441 | Googal | Network (BOI15_net) | C++14 | 792 ms | 155572 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 <iostream>
#include <vector>
using namespace std;
const int NMAX = 6 * 1e5 + 1e2;
int n;
int startn;
vector < int > g[1 + NMAX];
vector < int > res;
void dfs(int u, int v) {
if(g[u].size() == 1) {
res.push_back(u);
return;
}
for(int i = 0; i < g[u].size(); i++) {
if(g[u][i] == v)
continue;
dfs(g[u][i], u);
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i = 1; i <= n; i++) {
if(g[i].size() >= 2) {
startn = i;
break;
}
}
dfs(startn, -1);
int rsize = res.size();
cout << rsize / 2 + rsize % 2 << '\n';
for(int i = 0; i + rsize / 2 < rsize; i++)
cout << res[i] << ' ' << res[i + rsize / 2] << '\n';
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... |