Submission #1189090

#TimeUsernameProblemLanguageResultExecution timeMemory
1189090comxddddddNetwork (BOI15_net)C++20
0 / 100
0 ms324 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 <= n; i++)
    {
        if (net[i] == 1)
            con.push_back(i);
    }
    int center = 1;
    for (int i = 1; i <= n; i++)
    {
        if (net[i] > 1)
        {
            center = i;
            break;
        }
    }
    int leafCount = con.size();
    int pairs = (leafCount + 1) / 2;
    cout << pairs << "\n";
    int l = 0, r = leafCount - 1;
    while (l < r)
    {
        cout << con[l] << " " << con[r] << "\n";
        l++;
        r--;
    }
    if (l == r)
    {
        cout << con[l] << " " << center << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...