結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
tekitouk
|
| 提出日時 | 2015-09-05 03:21:20 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,158 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 21,248 KB |
| 実行使用メモリ | 9,252 KB |
| 最終ジャッジ日時 | 2024-07-19 03:39:27 |
| 合計ジャッジ時間 | 4,986 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 2 TLE * 1 -- * 10 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:19:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d",&N);
| ^~~~~~~~~~~~~~
main.c:23:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | 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 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++){
DEPTH = 9999999;
leaf_search(0, i);
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>MAX_DEPTH){ return; }
int i;
int cnt = 0;
for (i = 0; i < N - 1; i++){
if (x[i] == now){
cnt++;
}
}
if (cnt == 0){ DEPTH = min(DEPTH, depth); 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; }
}
tekitouk