結果
問題 |
No.277 根掘り葉掘り
|
ユーザー |
![]() |
提出日時 | 2015-09-05 03:11:48 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,222 bytes |
コンパイル時間 | 578 ms |
コンパイル使用メモリ | 21,376 KB |
実行使用メモリ | 9,248 KB |
最終ジャッジ日時 | 2024-07-19 03:39:01 |
合計ジャッジ時間 | 5,598 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 WA * 2 TLE * 1 -- * 10 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:20:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d",&N); | ^~~~~~~~~~~~~~ main.c:24:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d %d", &x[i], &y[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int x[100000] = { 0 }; int y[100000] = { 0 }; int R[100000] = { 0 }; int L[100000] = { 0 }; int N; void root_search(int depth,int now); void leaf_search(int depth, int now); int min(int a, int b); int flag; int MAX_DEPTH = 0;; int DEPTH; int main(){ scanf("%d",&N); int i; for (i = 0; i < N - 1; i++){ scanf("%d %d", &x[i], &y[i]); x[i]--; y[i]--; } root_search(0, 0); for (i = 0; i < N; i++){ for (DEPTH = 0; DEPTH <= MAX_DEPTH; DEPTH++){ flag = 0; leaf_search(0, i); if (flag == 1){ break; } } L[i] = DEPTH; } for (i = 0; i < N; i++){ printf("%d\n",min(R[i],L[i])); } return 0; } void root_search(int depth,int now){ if (MAX_DEPTH < depth){ MAX_DEPTH = depth; } R[now] = depth; int i; for (i = 0; i < N - 1; i++){ if (x[i] == now){ root_search(depth + 1, y[i]); } } } void leaf_search(int depth, int now){ if (depth>DEPTH){ return; } int i; int cnt = 0; for (i = 0; i < N - 1; i++){ if (x[i] == now){ cnt++; } } if (cnt == 0){ flag = 1; return; } else{ for (i = 0; i < N - 1; i++){ if (x[i] == now){ leaf_search(depth + 1, y[i]); } } } } int min(int a, int b){ if (a >= b){ return b; } else{ return a; } }