# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
137064 | silxikys | Network (BOI15_net) | C++14 | 15 ms | 12156 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;
using ll = long long;
const int maxn = 5e5+5;
int n;
vector<int> adj[maxn];
int deg[maxn];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b; cin >> a >> b;
++deg[a];
++deg[b];
}
vector<int> leafs;
for (int i = 1; i <= n; i++) {
if (deg[i] == 1) leafs.push_back(i);
}
vector<pair<int,int>> ans;
for (int i = 0; i < leafs.size(); i += 2) {
ans.push_back({leafs[i],leafs[(i+1)%leafs.size()]});
}
//output
cout << ans.size() << '\n';
for (auto p: ans) {
cout << p.first << ' ' << p.second << '\n';
}
}
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... |