結果

問題 No.277 根掘り葉掘り
ユーザー nasadigitalnasadigital
提出日時 2015-09-06 23:15:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 150,476 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-09-26 09:49:32
合計ジャッジ時間 5,044 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 173 ms
6,636 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>

using namespace std;

typedef vector<int> vi;
vector<vi> adjList;
int rez[100001];

int dfs(int cur,int d){
    int md=9999999;
    if(adjList[cur].size()==0)
    {
        rez[cur]=0;
        return 0;
    }
    for(int ctr1=0;ctr1<adjList[cur].size();ctr1++){
        md=min(md,1+dfs(adjList[cur][ctr1],d+1));
    }
    rez[cur]=min(d,md);
    return md;
}

int main()
{

    int n;
    cin>>n;
    for(int ctr1=0;ctr1<n;ctr1++)
    {
        vi t;
        adjList.push_back(t);
        rez[ctr1]=9999999;
    }
    for(int ctr1=0;ctr1<n-1;ctr1++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        adjList[x].push_back(y);
    }
    dfs(0,0);
    for(int ctr1=0;ctr1<n;ctr1++)
        cout<<rez[ctr1]<<endl;
    return 0;
}
0