結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-09-05 00:58:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 831 bytes |
| コンパイル時間 | 257 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-07-19 02:58:08 |
| 合計ジャッジ時間 | 3,052 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 1 RE * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#define MAX 100000
int calc(int, int);
int lr[3][MAX], count[MAX], memo[MAX], ne[MAX], ha[MAX];
int main(void) {
int n, i;
scanf("%d", &n);
for(i = 0; i < n - 1; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--; y--;
lr[ count[x] ][x] = y; count[x]++;
lr[ count[y] ][y] = x; count[y]++;
}
calc(0, 0);
for(i = 0; i < n; i++) {
printf("%d\n", ne[i] < ha[i] ? ne[i] : ha[i]);
}
return 0;
}
int calc(int i, int c) {
ne[i] = c;
memo[i] = 1;
int m = MAX, temp;
if(memo[ lr[0][i] ] == 0) { temp = calc(lr[0][i], c + 1) + 1; m = (temp < m ? temp : m); }
if(memo[ lr[1][i] ] == 0) { temp = calc(lr[1][i], c + 1) + 1; m = (temp < m ? temp : m); }
if(memo[ lr[2][i] ] == 0) { temp = calc(lr[2][i], c + 1) + 1; m = (temp < m ? temp : m); }
m = (m == MAX ? 0 : m);
ha[i] = m;
return m;
}
FF256grhy