Submission #527509

# Submission time Handle Problem Language Result Execution time Memory
527509 2022-02-17T14:03:09 Z jalsol Network (BOI15_net) C++11
100 / 100
421 ms 47520 KB
#include <bits/stdc++.h>

using namespace std;

#define Task ""

struct __Init__ {
    __Init__() {
        cin.tie(nullptr)->sync_with_stdio(false);
        if (fopen(Task".inp", "r")) {
            freopen(Task".inp", "r", stdin);
            freopen(Task".out", "w", stdout); }
    }
} __init__;

using ll = long long;

#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)

template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxN = 5e5 + 5;

int n;
vector<int> g[maxN];

vector<int> child;

void Dfs(int u, int p) {
    bool hasChild = false;

    for (int v : g[u]) {
        if (v != p) {
            hasChild = true;
            Dfs(v, u);
        }
    }

    if (!hasChild) {
        child.push_back(u);
    }
}

signed main() {
    cin >> n;

    For (i, 1, n - 1) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int root = -1;
    For (i, 1, n) {
        if (isz(g[i]) > 1) {
            root = i;
            break;
        }
    }

    child.reserve(n);
    Dfs(root, -1);

    int ans = (isz(child) + 1) / 2;
    cout << ans << '\n';

    Rep (i, ans) {
        cout << child[i] << ' ' << child[i + isz(child) / 2] << '\n';
    }
}

/*

*/

Compilation message

net.cpp: In constructor '__Init__::__Init__()':
net.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             freopen(Task".inp", "r", stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             freopen(Task".out", "w", stdout); }
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 12016 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12036 KB Output is correct
5 Correct 7 ms 12052 KB Output is correct
6 Correct 6 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 6 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 12044 KB Output is correct
12 Correct 6 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 12016 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12036 KB Output is correct
5 Correct 7 ms 12052 KB Output is correct
6 Correct 6 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 6 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 12044 KB Output is correct
12 Correct 6 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11968 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12172 KB Output is correct
23 Correct 8 ms 12160 KB Output is correct
24 Correct 7 ms 12108 KB Output is correct
25 Correct 7 ms 12108 KB Output is correct
26 Correct 7 ms 12108 KB Output is correct
27 Correct 8 ms 12044 KB Output is correct
28 Correct 7 ms 12108 KB Output is correct
29 Correct 7 ms 12108 KB Output is correct
30 Correct 6 ms 11980 KB Output is correct
31 Correct 8 ms 12108 KB Output is correct
32 Correct 6 ms 12056 KB Output is correct
33 Correct 7 ms 11996 KB Output is correct
34 Correct 6 ms 11980 KB Output is correct
35 Correct 7 ms 11980 KB Output is correct
36 Correct 7 ms 11984 KB Output is correct
37 Correct 7 ms 12108 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 6 ms 11948 KB Output is correct
40 Correct 7 ms 12052 KB Output is correct
41 Correct 6 ms 12064 KB Output is correct
42 Correct 7 ms 12060 KB Output is correct
43 Correct 7 ms 12108 KB Output is correct
44 Correct 7 ms 11980 KB Output is correct
45 Correct 6 ms 12060 KB Output is correct
46 Correct 6 ms 12056 KB Output is correct
47 Correct 7 ms 12056 KB Output is correct
48 Correct 7 ms 12108 KB Output is correct
49 Correct 7 ms 12064 KB Output is correct
50 Correct 8 ms 11980 KB Output is correct
51 Correct 6 ms 11980 KB Output is correct
52 Correct 7 ms 12056 KB Output is correct
53 Correct 7 ms 11980 KB Output is correct
54 Correct 7 ms 12052 KB Output is correct
55 Correct 7 ms 12060 KB Output is correct
56 Correct 7 ms 12056 KB Output is correct
57 Correct 7 ms 12060 KB Output is correct
58 Correct 7 ms 12060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 12016 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12036 KB Output is correct
5 Correct 7 ms 12052 KB Output is correct
6 Correct 6 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 12040 KB Output is correct
9 Correct 6 ms 11980 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 7 ms 12044 KB Output is correct
12 Correct 6 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11968 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12172 KB Output is correct
23 Correct 8 ms 12160 KB Output is correct
24 Correct 7 ms 12108 KB Output is correct
25 Correct 7 ms 12108 KB Output is correct
26 Correct 7 ms 12108 KB Output is correct
27 Correct 8 ms 12044 KB Output is correct
28 Correct 7 ms 12108 KB Output is correct
29 Correct 7 ms 12108 KB Output is correct
30 Correct 6 ms 11980 KB Output is correct
31 Correct 8 ms 12108 KB Output is correct
32 Correct 6 ms 12056 KB Output is correct
33 Correct 7 ms 11996 KB Output is correct
34 Correct 6 ms 11980 KB Output is correct
35 Correct 7 ms 11980 KB Output is correct
36 Correct 7 ms 11984 KB Output is correct
37 Correct 7 ms 12108 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 6 ms 11948 KB Output is correct
40 Correct 7 ms 12052 KB Output is correct
41 Correct 6 ms 12064 KB Output is correct
42 Correct 7 ms 12060 KB Output is correct
43 Correct 7 ms 12108 KB Output is correct
44 Correct 7 ms 11980 KB Output is correct
45 Correct 6 ms 12060 KB Output is correct
46 Correct 6 ms 12056 KB Output is correct
47 Correct 7 ms 12056 KB Output is correct
48 Correct 7 ms 12108 KB Output is correct
49 Correct 7 ms 12064 KB Output is correct
50 Correct 8 ms 11980 KB Output is correct
51 Correct 6 ms 11980 KB Output is correct
52 Correct 7 ms 12056 KB Output is correct
53 Correct 7 ms 11980 KB Output is correct
54 Correct 7 ms 12052 KB Output is correct
55 Correct 7 ms 12060 KB Output is correct
56 Correct 7 ms 12056 KB Output is correct
57 Correct 7 ms 12060 KB Output is correct
58 Correct 7 ms 12060 KB Output is correct
59 Correct 293 ms 30520 KB Output is correct
60 Correct 350 ms 38660 KB Output is correct
61 Correct 6 ms 11980 KB Output is correct
62 Correct 6 ms 11980 KB Output is correct
63 Correct 249 ms 33432 KB Output is correct
64 Correct 8 ms 12484 KB Output is correct
65 Correct 14 ms 13828 KB Output is correct
66 Correct 106 ms 27812 KB Output is correct
67 Correct 386 ms 46908 KB Output is correct
68 Correct 402 ms 47520 KB Output is correct
69 Correct 11 ms 12740 KB Output is correct
70 Correct 66 ms 21152 KB Output is correct
71 Correct 255 ms 41740 KB Output is correct
72 Correct 251 ms 40532 KB Output is correct
73 Correct 68 ms 18848 KB Output is correct
74 Correct 394 ms 37572 KB Output is correct
75 Correct 26 ms 15084 KB Output is correct
76 Correct 273 ms 41412 KB Output is correct
77 Correct 266 ms 41440 KB Output is correct
78 Correct 28 ms 15392 KB Output is correct
79 Correct 421 ms 45176 KB Output is correct
80 Correct 8 ms 12180 KB Output is correct
81 Correct 104 ms 21120 KB Output is correct
82 Correct 352 ms 39388 KB Output is correct
83 Correct 381 ms 37568 KB Output is correct
84 Correct 377 ms 37620 KB Output is correct
85 Correct 405 ms 37496 KB Output is correct
86 Correct 367 ms 38600 KB Output is correct
87 Correct 341 ms 38684 KB Output is correct