Submission #546667

#TimeUsernameProblemLanguageResultExecution timeMemory
546667JomnoiNetwork (BOI15_net)C++17
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 5e5 + 10;

int degree[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n - 1; i++) {
        int a, b;
        cin >> a >> b;
        degree[a]++;
        degree[b]++;
    }

    vector <int> vec;
    for(int i = 1; i <= n; i++) {
        if(degree[i] == 1) {
            vec.push_back(i);
        }
    }

    cout << (vec.size() + 1) / 2 << '\n';
    for(int i = 1; i < vec.size(); i += 2) {
        cout << vec[i - 1] << ' ' << vec[i] << '\n';
    }
    if(vec.size() % 2 == 1) {
        cout << vec.back() << ' ' << vec.front();
    }
    return 0;
}

Compilation message (stderr)

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