답안 #666769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666769 2022-11-29T16:10:05 Z divad Network (BOI15_net) C++14
0 / 100
6 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);
    }
    dfs(1);
    //sort(frunze.begin(), frunze.end());
    reverse(frunze.begin(), frunze.end());
    vector<pair<int, int>> sol;
    sol.push_back({1, frunze[0]});
    for(int i = 1; i < frunze.size()-1; i++){
        sol.push_back({frunze[i], frunze[i+1]});
    }
    cout << sol.size() << "\n";
    for(auto [x, y]: sol){
        cout << x << " " << y << "\n";
    }
    return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 1; i < frunze.size()-1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~
net.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |     for(auto [x, y]: sol){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 11988 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 11988 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 11988 KB Breaking single line is causing network to disconnect.
2 Halted 0 ms 0 KB -