# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382068 | Aryan_Raina | Network (BOI15_net) | C++14 | 1 ms | 492 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;
#define int long long
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 1e9 + 7;
const int MXN = 5e5+9;
int cnt[MXN];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin>>n;
for (int i = 0; i < n-1; i++) {
int a, b; cin>>a>>b; --a, --b;
cnt[a]++, cnt[b]++;
}
vector<int> outer;
for (int i = 0; i < n; i++) if (cnt[i] == 1) outer.push_back(i+1);
cout<<(outer.size()+1)/2<<"\n";
for (int i = 1; i < outer.size(); i+=2) {
cout<<outer[i]<<" "<<outer[i-1]<<"\n";
}
if (outer.size() % 2 == 1) cout<<outer.back()<<" 1\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... |