Submission #959592

#TimeUsernameProblemLanguageResultExecution timeMemory
959592BlagojNetwork (BOI15_net)C++17
0 / 100
1 ms500 KiB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

const int mxn = 5e5 + 10;

int deg[mxn];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int f, t;
        cin >> f >> t;
        deg[f]++;
        deg[t]++;
    }
    vector<int> leafs;
    for (int i = 1; i <= n; i++) if (deg[i] == 1) leafs.push_back(i);
    cout << leafs.size() / 2 + (leafs.size() % 2 != 0) << endl;
    for (int i = 0; i < leafs.size() - 1; i += 2) cout << leafs[i] << " " << leafs[i + 1] << endl;
    if (leafs.size() % 2 == 1) cout << leafs[0] << " " << leafs[leafs.size() - 1] << endl;
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < leafs.size() - 1; i += 2) cout << leafs[i] << " " << leafs[i + 1] << endl;
      |                     ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...