結果

問題 No.277 根掘り葉掘り
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-11 11:29:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 4,453 ms
コンパイル使用メモリ 206,592 KB
実行使用メモリ 17,012 KB
最終ジャッジ日時 2023-10-21 15:34:30
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 231 ms
17,012 KB
testcase_10 AC 198 ms
9,656 KB
testcase_11 AC 220 ms
9,092 KB
testcase_12 AC 224 ms
13,052 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/277/
#include <bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> G;
vector<int> book;

int maine(int idx, int par, int depth) {
    int ret = N;
    if (G[idx].size() == 1)
        ret = 0;
    for (auto&& nxt : G[idx]) {
        if (nxt == par)
            continue;
        ret = min(ret, maine(nxt, idx, depth + 1) + 1);
    }
    book[idx] = min(depth, ret);
    return ret;
}

int main() {
    cin >> N;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }
    book.resize(N);
    maine(0, -1, 0);
    for (auto&& a : book) {
        cout << a << endl;
    }
}
0