# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69459 | kingpig9 | Network (BOI15_net) | C++11 | 698 ms | 154532 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>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug(...)
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#define fi first
#define se second
int N;
vector<int> adj[500010];
vector<int> leaves;
void dfs (int x, int p) {
if (adj[x].size() == 1) {
leaves.push_back(x);
}
for (int y : adj[x]) {
if (y != p) {
dfs(y, x);
}
}
}
int main() {
scanf("%d", &N);
for (int i = 1; i < N; i++) {
int x, y;
scanf("%d %d", &x, &y);
adj[x].push_back(y);
adj[y].push_back(x);
}
int root = 1;
while (adj[root].size() == 1) {
root++;
}
dfs(root, -1);
vector<pii> ans;
for (int i = 0, j = leaves.size() / 2; j < leaves.size(); i++, j++) {
ans.push_back({leaves[i], leaves[j]});
}
printf("%lu\n", ans.size());
for (pii p : ans) {
printf("%d %d\n", p.fi, p.se);
}
}
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... |