Submission #1350334

#TimeUsernameProblemLanguageResultExecution timeMemory
1350334Zone_zoneeNetwork (BOI15_net)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+10;

int in[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for(int i = 1; i < n; ++i){
        int u, v;
        cin >> u >> v;
        in[u]++;
        in[v]++;
    }
    vector<int> leaf;
    int not_leaf;
    for(int i = 1; i <= n; ++i){
        if(in[i] == 1) leaf.push_back(i);
        else not_leaf = i;
    }
    cout << (int(leaf.size())+1)/2 << '\n';
    for(int i = 0; i < int(leaf.size())-1; i += 2){
        cout << leaf[i] << ' ' << leaf[i+1] << '\n';
    }
    if(int(leaf.size())&1) cout << leaf.back() << ' ' << leaf.front() << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...