Submission #666801

# Submission time Handle Problem Language Result Execution time Memory
666801 2022-11-29T18:16:53 Z divad Network (BOI15_net) C++14
0 / 100
8 ms 11988 KB
#include <iostream>
#include <algorithm>
#include <vector>
#define MAX 500002
using namespace std;
int n,x,y,vf[MAX];
vector<int> v[MAX],frunze;

void dfs(int nod){
    vf[nod] = 1;
    bool ok = false;
    for(auto vecin: v[nod]){
        if(vf[vecin] == 0){
            ok |= true;
            dfs(vecin);
        }
    }
    if(!ok){
        frunze.push_back(nod);
    }
}

int main()
{
    cin >> n;
    for(int i = 1; i < n; i++){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int rad = 1;
    for(int i = 1; i <= n; i++){
        if(v[i].size() > 1){
            rad = i;
        }
    }
    dfs(rad);
    if(frunze.size()%2 == 0){
        cout << frunze.size()/2 << "\n";
        for(int i = 0; i < frunze.size()/2; i++){
            cout << frunze[i] << " " << frunze[i + frunze.size()/2] << "\n";
        }
    }else{
        cout << (frunze.size()/2)+1 << "\n";
        for(int i = 0; i < frunze.size()/2; i++){
            cout << frunze[i] << " " << frunze[i + frunze.size()/2] << "\n";
        }
        cout << frunze[frunze.size()-1] << " " << rad;
    }
    return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i = 0; i < frunze.size()/2; i++){
      |                        ~~^~~~~~~~~~~~~~~~~
net.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int i = 0; i < frunze.size()/2; i++){
      |                        ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
5 Halted 0 ms 0 KB -