結果

問題 No.277 根掘り葉掘り
ユーザー kappybarkappybar
提出日時 2020-05-01 17:55:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 170,668 KB
実行使用メモリ 17,120 KB
最終ジャッジ日時 2023-08-26 00:00:03
合計ジャッジ時間 6,200 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,960 KB
testcase_01 AC 3 ms
6,064 KB
testcase_02 WA -
testcase_03 AC 5 ms
6,068 KB
testcase_04 AC 5 ms
6,096 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
6,196 KB
testcase_09 AC 223 ms
17,120 KB
testcase_10 AC 197 ms
9,604 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using pll = pair<ll,ll>;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr int MOD = 1000000007;
int n = 100005;
vector<vector<int>> tree(n,vector<int>());
vector<int> R(n,0);
vector<int> L(n,0);

int dfs(int i,int p=-1,int d=0){
    R[i] = d;
    int res = 0;
    for(int c:tree[i]){
        if(c == p) continue;
        res = max(res,dfs(c,i,d+1)+1);
    }
    L[i] = res;
    return L[i];
}

int main(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0);
    rep(i,n){
        cout << min(L[i],R[i]) << endl;
    }
    return 0;
}
0