結果

問題 No.277 根掘り葉掘り
ユーザー ゆぽゆぽ
提出日時 2016-05-28 01:01:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,344 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 89,732 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-16 18:00:58
合計ジャッジ時間 5,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,144 KB
testcase_01 AC 4 ms
6,016 KB
testcase_02 WA -
testcase_03 AC 4 ms
6,144 KB
testcase_04 AC 3 ms
6,272 KB
testcase_05 AC 4 ms
6,016 KB
testcase_06 AC 4 ms
6,016 KB
testcase_07 AC 4 ms
5,888 KB
testcase_08 AC 3 ms
6,016 KB
testcase_09 AC 229 ms
17,152 KB
testcase_10 AC 194 ms
9,340 KB
testcase_11 AC 219 ms
9,088 KB
testcase_12 AC 222 ms
12,928 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int N;
vector<int> es[100000];
int res[100000];

int solve(int v, int h, int p) {
	if (v != 0 && es[v].size() == 1) {
		res[v] = 0;
		return 0;
	}
	int r = 100000;
	REP(i, es[v].size()) if (es[v][i] != p) r = min(r, solve(es[v][i], h + 1, v));
	res[v] = min(h, r + 1);
	return r + 1;
}

int main(int argc, char **argv) {
	cin >> N;
	REP(i, N - 1) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		es[x].push_back(y);
		es[y].push_back(x);
	}
	CLEAR(res);
	solve(0, 0, 0);
	REP(i, N) cout << res[i] << endl;
	return 0;
}
0