Submission #1038216

#TimeUsernameProblemLanguageResultExecution timeMemory
1038216codexistentNetwork (BOI15_net)C++14
0 / 100
2 ms12124 KiB
#include <bits/stdc++.h>
using namespace std;
#define MAXN 500005
#define FOR(i, a, b) for(int i = a; i <= b; i++)

int n;
vector<int> e[MAXN];

int main(){
    cin >> n;
    FOR(i, 1, n - 1){
        int a, b; 
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a); 
    }

    vector<int> n2;
    FOR(i, 1, n){
        if(e[i].size() == 1){
            n2.push_back(i);
        }
    }

    cout << (n2.size() + 1) / 2 << endl;
    FOR(i, 0, n2.size() - 1){
        if(i == n2.size() - 1){
            cout << 1 << " " << n2[i] << endl;
        }else{
            cout << n2[i] << " " << n2[i + 1] << endl;
        }
    }
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, a, b) for(int i = a; i <= b; i++)
......
   26 |     FOR(i, 0, n2.size() - 1){
      |         ~~~~~~~~~~~~~~~~~~~            
net.cpp:26:5: note: in expansion of macro 'FOR'
   26 |     FOR(i, 0, n2.size() - 1){
      |     ^~~
net.cpp:27:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if(i == n2.size() - 1){
      |            ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...