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;
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> ii;
const int N = 5e5 + 10;
const int oo = 1e9;
int n;
int deg[N];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
deg[u] ++; deg[v] ++;
}
vector<ii> ans;
int las = -1;
for(int i = 1; i <= n; ++i) if(deg[i] == 1) {
if(las == -1) las = i;
else ans.pb({i, las}), las = -1;
}
if(las != -1) for(int i = 1; i <= n; ++i) if(deg[i] == 1) {
ans.pb(ii(las, i)); break;
}
cout << ans.size() << '\n';
for(ii v: ans) cout << v.fi << ' ' << v.se << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |