結果

問題 No.2532 Want Play More
ユーザー 👑 chro_96chro_96
提出日時 2023-11-03 22:49:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 29,260 KB
実行使用メモリ 21,424 KB
最終ジャッジ日時 2023-11-03 22:50:04
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,052 KB
testcase_01 AC 81 ms
12,064 KB
testcase_02 AC 74 ms
12,064 KB
testcase_03 AC 70 ms
12,064 KB
testcase_04 AC 61 ms
12,068 KB
testcase_05 AC 59 ms
12,068 KB
testcase_06 AC 51 ms
21,424 KB
testcase_07 AC 4 ms
12,052 KB
testcase_08 AC 5 ms
12,052 KB
testcase_09 AC 5 ms
12,052 KB
testcase_10 AC 28 ms
12,060 KB
testcase_11 AC 28 ms
12,060 KB
testcase_12 AC 46 ms
12,064 KB
testcase_13 AC 39 ms
12,060 KB
testcase_14 AC 12 ms
12,056 KB
testcase_15 AC 65 ms
12,068 KB
testcase_16 AC 58 ms
12,060 KB
testcase_17 AC 5 ms
12,052 KB
testcase_18 AC 38 ms
12,060 KB
testcase_19 AC 54 ms
12,064 KB
testcase_20 AC 3 ms
12,052 KB
testcase_21 AC 4 ms
12,052 KB
testcase_22 AC 4 ms
12,052 KB
testcase_23 AC 4 ms
12,052 KB
testcase_24 AC 4 ms
12,052 KB
testcase_25 AC 4 ms
12,052 KB
testcase_26 AC 4 ms
12,052 KB
testcase_27 AC 4 ms
12,052 KB
testcase_28 AC 40 ms
12,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct list {
  int v;
  struct list *n;
} list;

void func (int v, list **e, int *visited, int ans[][2]) {
  list *l = e[v];
  
  visited[v] = 1;
  ans[v][0] = 0;
  ans[v][1] = 0;
  while (l != NULL) {
    if (visited[l->v] <= 0) {
      func(l->v, e, visited, ans);
      if (ans[v][0] < ans[l->v][1]+1) {
        ans[v][0] = ans[l->v][1]+1;
      }
      if (ans[v][1] <= 0 || ans[v][1] > ans[l->v][0]+1) {
        ans[v][1] = ans[l->v][0]+1;
      }
    }
    l = l->n;
  }
  
  return;
}

int main () {
  int n = 0;
  int a = 0;
  int b = 0;
  
  int res = 0;
  
  int ans[200000][2] = {};
  list *e[200000] = {};
  
  list pool[399998] = {};
  int used = 0;
  
  int visited[200000] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n-1; i++) {
    res = scanf("%d", &a);
    res = scanf("%d", &b);
    a--;
    b--;
    pool[used].v = b;
    pool[used].n = e[a];
    e[a] = pool+used;
    used++;
    pool[used].v = a;
    pool[used].n = e[b];
    e[b] = pool+used;
    used++;
  }
  
  func(0, e, visited, ans);
  
  printf("%d\n%d\n", ans[0][0], ans[0][1]);
  return 0;
}
0