結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-09-05 01:21:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 702 bytes |
| コンパイル時間 | 123 ms |
| コンパイル使用メモリ | 23,168 KB |
| 実行使用メモリ | 41,600 KB |
| 最終ジャッジ日時 | 2024-07-19 03:02:14 |
| 合計ジャッジ時間 | 26,984 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 1 RE * 11 |
コンパイルメッセージ
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 10000
int calc(int, int);
int lr[MAX][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 v, int c) {
ne[v] = c;
memo[v] = 1;
int m = MAX, temp;
int i;
for(i = 0; i < count[v]; i++) {
if(memo[ lr[i][v] ] == 0) {
temp = calc(lr[i][v], c + 1) + 1;
m = (temp < m ? temp : m);
}
}
m = (m == MAX ? 0 : m);
ha[v] = m;
return m;
}
FF256grhy