結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
唐澤貴洋
|
| 提出日時 | 2015-10-12 21:03:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,008 bytes |
| コンパイル時間 | 522 ms |
| コンパイル使用メモリ | 71,520 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-21 07:19:48 |
| 合計ジャッジ時間 | 5,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 3 TLE * 1 -- * 12 |
ソースコード
#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;
}
}
唐澤貴洋