結果

問題 No.277 根掘り葉掘り
ユーザー 唐澤貴洋唐澤貴洋
提出日時 2015-10-12 21:03:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 72,156 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-09-28 12:42:05
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 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 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<bitset>
#include<array>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstdlib>
#define D int
#define U unsigned
using namespace std;
D n, m,a, b, d, e, x, y, z;
D i, j, k;
struct Li {
	int n;
	int p;
	int r;
	int l;
	bool leaf;
	bool operator<(const Li &obj) const{
		return n < obj.n;
	}
};
Li tr[100000];
int main() {
	int t,u;
	cin >> a;
	tr[0].n = 0;
	tr[0].p = -1;
	tr[0].r = 0;
	tr[0].leaf = true;
	for (i = 1; i < a; i++) {
		cin >> tr[i].p >> tr[i].n;
		tr[i].p--;
		tr[i].n--;
	}
	sort(tr, tr + a);
	for (i = 1; i < a; i++) {
		tr[i].r = tr[tr[i].p].r + 1;
		if(tr[tr[i].p].leaf)
			tr[tr[i].p].leaf = false;
		tr[i].leaf = true;
	}
	for (i = 0; i < a; i++) {
		if (tr[i].leaf) {
			tr[i].l = 0;
			t = tr[i].p;
			u = i;
			while (t>=0) {
				tr[t].l = tr[u].l + 1;
				u = t;
				t = tr[t].p;
			}
		}
	}
	for (i = 0; i < a;i++) {
		cout << min(tr[i].r, tr[i].l) << endl;
	}
}
0