Submission #637470

#TimeUsernameProblemLanguageResultExecution timeMemory
637470bonkNetwork (BOI15_net)C++14
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5;
int d[N + 2];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        d[u]++;
        d[v]++;
    }

    vector<int>leaf;

    for(int i = 1; i <= n; i++){
        if(d[i] == 1) leaf.push_back(i);
    }

    int sz = leaf.size();

    cout << (sz + 1)/2 << '\n';
    if(sz&1) cout << leaf[0] << " " << leaf.back() << '\n';
    for(int i = 0; i < sz - 1; i += 2) cout << leaf[i] << " " << leaf[i + 1] << '\n';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...