結果

問題 No.2531 Coloring Vertices on Namori
ユーザー 👑 chro_96chro_96
提出日時 2023-11-03 23:47:35
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 29,868 KB
実行使用メモリ 12,652 KB
最終ジャッジ日時 2023-11-03 23:47:43
合計ジャッジ時間 4,446 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

typedef struct tree {
  struct tree *p;
} tree;

tree *get_root (tree *t) {
  if (t == NULL || t->p == NULL) {
    return t;
  }
  
  t->p = get_root(t->p);
  return t->p;
}

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 k = 0;
  int u = 0;
  int v = 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", &u);
    res = scanf("%d", &u);
    u--;
    v--;
    pool[used].v = v;
    pool[used].n = e[u];
    e[u] = pool+used;
    used++;
    pool[used].v = u;
    pool[used].n = e[v];
    e[v] = pool+used;
    used++;
  }
  
  func(0, e, visited, ans);
  
  printf("%d\n%d\n", ans[0][0], ans[0][1]);
  return 0;
}
0