Submission #144944

# Submission time Handle Problem Language Result Execution time Memory
144944 2019-08-18T08:48:38 Z Vlatko Network (BOI15_net) C++14
0 / 100
13 ms 12152 KB
#include <bits/stdc++.h>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef pair<int, int> pii;


const int maxn = 500050;

int n;
vector<int> adj[maxn];
vector<int> leaves;
vector<pii> edges;

void dfs(int u, int p) {
    if (adj[u].size() == 1 && (adj[u][0] == p || p == -1)) {
        leaves.push_back(u);
    }
    for (int v : adj[u]) {
        if (v != p) {
            dfs(v, u);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, -1);
    int k = leaves.size();
    edges.emplace_back(leaves[0], leaves[k-1]);
    for (int i = 1; i <= k-2; i += 2) {
        edges.emplace_back(leaves[i], leaves[i+1]);
    }
    cout << edges.size() << endl;
    for (auto &p : edges) {
        cout << p.first << ' ' << p.second << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 13 ms 12020 KB Output is correct
3 Correct 12 ms 12024 KB Output is correct
4 Correct 13 ms 12024 KB Output is correct
5 Correct 12 ms 12120 KB Output is correct
6 Correct 12 ms 12152 KB Output is correct
7 Correct 12 ms 12024 KB Output is correct
8 Incorrect 12 ms 12024 KB Breaking single line is causing network to disconnect.
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 13 ms 12020 KB Output is correct
3 Correct 12 ms 12024 KB Output is correct
4 Correct 13 ms 12024 KB Output is correct
5 Correct 12 ms 12120 KB Output is correct
6 Correct 12 ms 12152 KB Output is correct
7 Correct 12 ms 12024 KB Output is correct
8 Incorrect 12 ms 12024 KB Breaking single line is causing network to disconnect.
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 13 ms 12020 KB Output is correct
3 Correct 12 ms 12024 KB Output is correct
4 Correct 13 ms 12024 KB Output is correct
5 Correct 12 ms 12120 KB Output is correct
6 Correct 12 ms 12152 KB Output is correct
7 Correct 12 ms 12024 KB Output is correct
8 Incorrect 12 ms 12024 KB Breaking single line is causing network to disconnect.
9 Halted 0 ms 0 KB -