Submission #48962744


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

class Tree {
  public:
    int n;
    vector<int> tin, tout;
    vector<vector<int>> adj;
    int timer = 0;
    Tree(int n) {
        this->n = n;
        adj.resize(n);
        tin.resize(n);
        tout.resize(n);
    }

  public:
    void dfs(int src, int par) {
        tin[src] = ++timer;
        for (auto child : adj[src]) {
            if (child != par) {
                dfs(child, src);
            }
        }
        tout[src] = ++timer;
    }
};

void solve() {
    int n;
    cin >> n;
    Tree t(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        t.adj[u].push_back(v);
        t.adj[v].push_back(u);
    }

    t.dfs(0, -1);
    vector<int> child_subtree_sizes_of_root;
    for (auto child : t.adj[0]) {
        int sz = (t.tout[child] - t.tin[child] + 1) / 2;
        child_subtree_sizes_of_root.push_back(sz);
    }

    sort(child_subtree_sizes_of_root.begin(),
         child_subtree_sizes_of_root.end());
    child_subtree_sizes_of_root.pop_back();
    cout << 1 + accumulate(child_subtree_sizes_of_root.begin(),
                           child_subtree_sizes_of_root.end(), 0)
         << endl;
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task D - Erase Leaves
User adaptatron
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1335 Byte
Status AC
Exec Time 257 ms
Memory 31864 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3444 KiB
00_sample_01.txt AC 1 ms 3512 KiB
00_sample_02.txt AC 1 ms 3652 KiB
01_random_03.txt AC 137 ms 26080 KiB
01_random_04.txt AC 257 ms 31828 KiB
01_random_05.txt AC 190 ms 21804 KiB
01_random_06.txt AC 135 ms 26072 KiB
01_random_07.txt AC 236 ms 31864 KiB
01_random_08.txt AC 191 ms 21936 KiB
01_random_09.txt AC 151 ms 23160 KiB
01_random_10.txt AC 236 ms 27640 KiB
01_random_11.txt AC 197 ms 21872 KiB
01_random_12.txt AC 197 ms 22044 KiB
01_random_13.txt AC 151 ms 23176 KiB
01_random_14.txt AC 233 ms 30040 KiB
01_random_15.txt AC 192 ms 21792 KiB
01_random_16.txt AC 203 ms 22120 KiB
01_random_17.txt AC 157 ms 23104 KiB
01_random_18.txt AC 237 ms 28716 KiB
01_random_19.txt AC 194 ms 21844 KiB
01_random_20.txt AC 196 ms 22152 KiB
01_random_21.txt AC 160 ms 23164 KiB
01_random_22.txt AC 240 ms 31688 KiB
01_random_23.txt AC 193 ms 21760 KiB
01_random_24.txt AC 198 ms 22044 KiB
01_random_25.txt AC 21 ms 7292 KiB
01_random_26.txt AC 27 ms 8052 KiB
01_random_27.txt AC 98 ms 13696 KiB
01_random_28.txt AC 24 ms 6344 KiB
01_random_29.txt AC 112 ms 21328 KiB
01_random_30.txt AC 218 ms 21240 KiB
01_random_31.txt AC 142 ms 17632 KiB
01_random_32.txt AC 93 ms 18860 KiB
01_random_33.txt AC 72 ms 13972 KiB
01_random_34.txt AC 186 ms 21360 KiB
01_random_35.txt AC 13 ms 4868 KiB
01_random_36.txt AC 22 ms 7572 KiB
01_random_37.txt AC 78 ms 11568 KiB
01_random_38.txt AC 4 ms 3776 KiB
01_random_39.txt AC 157 ms 23172 KiB
01_random_40.txt AC 236 ms 26876 KiB
01_random_41.txt AC 191 ms 21820 KiB
01_random_42.txt AC 199 ms 22096 KiB
01_random_43.txt AC 150 ms 23204 KiB
01_random_44.txt AC 236 ms 26836 KiB
01_random_45.txt AC 192 ms 21836 KiB
01_random_46.txt AC 198 ms 22292 KiB
01_random_47.txt AC 1 ms 3464 KiB
01_random_48.txt AC 1 ms 3540 KiB