結果

問題 No.2301 Namorientation
ユーザー 👑 chro_96chro_96
提出日時 2023-05-12 22:28:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 108 ms / 3,000 ms
コード長 1,569 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 17,676 KB
最終ジャッジ日時 2024-05-06 12:30:57
合計ジャッジ時間 9,527 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
14,304 KB
testcase_01 AC 6 ms
14,080 KB
testcase_02 AC 6 ms
14,180 KB
testcase_03 AC 6 ms
14,164 KB
testcase_04 AC 6 ms
14,208 KB
testcase_05 AC 6 ms
14,208 KB
testcase_06 AC 5 ms
14,256 KB
testcase_07 AC 6 ms
14,208 KB
testcase_08 AC 6 ms
14,208 KB
testcase_09 AC 5 ms
14,208 KB
testcase_10 AC 5 ms
14,156 KB
testcase_11 AC 6 ms
14,328 KB
testcase_12 AC 62 ms
14,208 KB
testcase_13 AC 57 ms
14,172 KB
testcase_14 AC 103 ms
14,188 KB
testcase_15 AC 70 ms
14,208 KB
testcase_16 AC 91 ms
14,256 KB
testcase_17 AC 68 ms
14,336 KB
testcase_18 AC 93 ms
14,328 KB
testcase_19 AC 52 ms
14,164 KB
testcase_20 AC 90 ms
14,208 KB
testcase_21 AC 65 ms
14,208 KB
testcase_22 AC 60 ms
17,664 KB
testcase_23 AC 60 ms
17,676 KB
testcase_24 AC 52 ms
17,152 KB
testcase_25 AC 42 ms
14,208 KB
testcase_26 AC 53 ms
14,208 KB
testcase_27 AC 108 ms
14,080 KB
testcase_28 AC 106 ms
14,208 KB
testcase_29 AC 108 ms
14,080 KB
testcase_30 AC 104 ms
14,080 KB
testcase_31 AC 107 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

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

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, int tmp_d, list **e, int *d) {
  list *l = e[v];
  
  if (d[v] > 0) {
    return;
  }
  
  d[v] = tmp_d;
  while (l != NULL) {
    func(l->v, tmp_d+1, e, d);
    l = l->n;
  }
  
  return;
}

int main () {
  int n = 0;
  int a[200000] = {};
  int b[200000] = {};
  
  int res = 0;
  
  int ans[200000] = {};
  
  int rt = 0;
  tree t[200000] = {};
  
  list pool[399998] = {};
  int used = 0;
  
  list *e[200000] = {};
  int d[200000] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    tree *rt1 = NULL;
    tree *rt2 = NULL;
    res = scanf("%d", a+i);
    res = scanf("%d", b+i);
    a[i]--;
    b[i]--;
    rt1 = get_root(t+a[i]);
    rt2 = get_root(t+b[i]);
    if (rt1 == rt2) {
      rt = a[i];
      ans[i] = 1;
    } else {
      rt2->p = rt1;
      pool[used].v = b[i];
      pool[used].n = e[a[i]];
      e[a[i]] = pool+used;
      used++;
      pool[used].v = a[i];
      pool[used].n = e[b[i]];
      e[b[i]] = pool+used;
      used++;
    }
  }
  
  func(rt, 1, e, d);
  
  for (int i = 0; i < n; i++) {
    if (ans[i] <= 0 && d[a[i]] < d[b[i]]) {
      ans[i] = 2;
    } else if (ans[i] <= 0) {
      ans[i] = 1;
    }
  }
  
  for (int i = 0; i < n; i++) {
    if (ans[i] == 1) {
      printf("->\n");
    } else {
      printf("<-\n");
    }
  }
  
  return 0;
}
0