結果

問題 No.277 根掘り葉掘り
ユーザー finefine
提出日時 2017-03-24 18:40:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 676 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 171,600 KB
実行使用メモリ 16,912 KB
最終ジャッジ日時 2023-09-20 06:05:47
合計ジャッジ時間 5,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 192 ms
16,912 KB
testcase_10 AC 165 ms
9,620 KB
testcase_11 AC 180 ms
9,364 KB
testcase_12 AC 190 ms
13,012 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;

const int INF = 1e7;

vector< vector<int> > G;
vector<int> R, L;

void dfs(int cur, int par) {
	for (int nex : G[cur]) {
		if (nex == par) continue;
		R[nex] = R[cur] + 1;
		dfs(nex, cur);
		L[cur] = min(L[cur], L[nex]);
	}
	if (L[cur] == INF) L[cur] = 0;
	else L[cur]++;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	G.resize(n);
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	R.resize(n, INF);
	L.resize(n, INF);
	R[0] = 0;
	dfs(0, -1);

	for (int i = 0; i < n; i++) {
		cout << min(R[i], L[i]) << endl;
	}
	return 0;
}
0