結果

問題 No.277 根掘り葉掘り
ユーザー 37kt_37kt_
提出日時 2015-10-17 22:29:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 3,484 ms
コンパイル使用メモリ 144,700 KB
実行使用メモリ 15,780 KB
最終ジャッジ日時 2023-09-29 16:56:52
合計ジャッジ時間 5,355 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,700 KB
testcase_01 AC 3 ms
5,700 KB
testcase_02 WA -
testcase_03 AC 3 ms
5,908 KB
testcase_04 AC 3 ms
5,672 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,684 KB
testcase_07 WA -
testcase_08 AC 3 ms
5,660 KB
testcase_09 AC 196 ms
15,780 KB
testcase_10 AC 166 ms
9,296 KB
testcase_11 WA -
testcase_12 AC 191 ms
12,724 KB
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;

int n;
vector<int> g[100000];
int r[100000], l[100000];

void dfs(int v, int p)
{
	for (int t : g[v]){
		if (t != p){
			r[t] = r[v] + 1;
			dfs(t, v);
			l[v] = l[t] + 1;
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	
	dfs(0, -1);
	
	for (int i = 0; i < n; i++){
		cout << min(r[i], l[i]) << endl;
	}
}
0