結果

問題 No.2202 贅沢てりたまチキン
ユーザー 👑 chro_96chro_96
提出日時 2023-02-03 21:37:55
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 29,788 KB
実行使用メモリ 4,984 KB
最終ジャッジ日時 2023-09-15 17:16:18
合計ジャッジ時間 2,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,892 KB
testcase_01 AC 1 ms
4,896 KB
testcase_02 AC 2 ms
4,848 KB
testcase_03 AC 2 ms
4,888 KB
testcase_04 AC 2 ms
4,892 KB
testcase_05 AC 2 ms
4,840 KB
testcase_06 AC 2 ms
4,884 KB
testcase_07 AC 2 ms
4,820 KB
testcase_08 AC 2 ms
4,892 KB
testcase_09 AC 2 ms
4,920 KB
testcase_10 AC 2 ms
4,840 KB
testcase_11 AC 2 ms
4,904 KB
testcase_12 AC 2 ms
4,852 KB
testcase_13 AC 2 ms
4,976 KB
testcase_14 AC 46 ms
4,788 KB
testcase_15 AC 47 ms
4,892 KB
testcase_16 AC 40 ms
4,984 KB
testcase_17 AC 40 ms
4,932 KB
testcase_18 AC 21 ms
4,984 KB
testcase_19 AC 24 ms
4,928 KB
testcase_20 AC 50 ms
4,900 KB
testcase_21 AC 49 ms
4,912 KB
testcase_22 AC 39 ms
4,912 KB
testcase_23 AC 43 ms
4,844 KB
testcase_24 AC 41 ms
4,808 KB
testcase_25 AC 67 ms
4,888 KB
testcase_26 AC 47 ms
4,892 KB
testcase_27 AC 46 ms
4,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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;
}

int main () {
  int n = 0;
  int m = 0;
  int a = 0;
  int b = 0;
  
  int res = 0;
  
  tree t[400000] = {};
  int is_ok = 1;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    tree *rt1 = NULL;
    tree *rt2 = NULL;
    res = scanf("%d", &a);
    res = scanf("%d", &b);
    a--;
    b--;
    rt1 = get_root(t+a);
    rt2 = get_root(t+(b+n));
    if (rt1 != rt2) {
      rt2->p = rt1;
    }
    rt1 = get_root(t+(a+n));
    rt2 = get_root(t+b);
    if (rt1 != rt2) {
      rt2->p = rt1;
    }
  }
  
  for (int i = 0; i < n; i++) {
    tree *rt1 = get_root(t+i);
    tree *rt2 = get_root(t+(i+n));
    if (rt1 != rt2) {
      is_ok = 0;
    }
  }
  
  if (is_ok > 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}
0