Submission #107187

# Submission time Handle Problem Language Result Execution time Memory
107187 2019-04-22T12:10:23 Z dolphingarlic Network (BOI15_net) C++14
0 / 100
14 ms 12160 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(int i = x; i < y; i++)
typedef long long ll;
using namespace std;

vector<int> graph[500001], leaves;

void dfs(int node, int parent = 0) {
    if (graph[node].size() == 1) leaves.push_back(node);
    for (auto& i : graph[node]) {
        if (i == parent) continue;
        dfs(i, node);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    FOR(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    cout << (leaves.size() + 1) / 2 << '\n';
    FOR(i, 0, leaves.size() / 2) cout << leaves[i] << ' ' << leaves[leaves.size() - i - 1] << '\n';
    if (leaves.size() & 1) cout << leaves[leaves.size() / 2] << " 1\n";
    return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:3:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, x, y) for(int i = x; i < y; i++)
net.cpp:30:9:
     FOR(i, 0, leaves.size() / 2) cout << leaves[i] << ' ' << leaves[leaves.size() - i - 1] << '\n';
         ~~~~~~~~~~~~~~~~~~~~~~~        
net.cpp:30:5: note: in expansion of macro 'FOR'
     FOR(i, 0, leaves.size() / 2) cout << leaves[i] << ' ' << leaves[leaves.size() - i - 1] << '\n';
     ^~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Incorrect 14 ms 12160 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Incorrect 14 ms 12160 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Incorrect 14 ms 12160 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -