Submission #1189062

#TimeUsernameProblemLanguageResultExecution timeMemory
1189062comxddddddNetwork (BOI15_net)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n,t1,t2;
    cin >> n;
    vector<int> net(n + 1,0);
    vector<vector<int>> conwith(n + 1);
    vector<int> con;
    for(int i = 1; i < n; i++){
        cin >> t1 >> t2;
        net[t1]++;
        net[t2]++;
        conwith[t1].emplace_back(t2);
        conwith[t2].emplace_back(t1);
    }
    int c = 0;
    for(int i = 1; i < net.size(); i++){
        if(net[i] == 1){
            c++;
            con.emplace_back(i);
        }
    }
    if(c % 2 == 1){
        c /= 2;
        c += 1;
    }
    else{
        c /= 2;
    }
    cout << c << '\n';
    while(con.size() > 1){
        t1 = con.back();
        con.pop_back();
        t2 = con.back();
        con.pop_back();
        cout << t1 << ' ' << t2 << '\n';
    }
    if(con.size() == 1){
        cout << con.back() << ' ';
        for(int i = 1; i < net.size(); i++){
            if(i != con.back() && find(conwith[con.back()].begin(),conwith[con.back()].end(),i) == conwith[con.back()].end()){
                cout << i << '\n';
                break;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...