結果

問題 No.1390 Get together
ユーザー kojihashimoto-kobekojihashimoto-kobe
提出日時 2021-11-25 10:46:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 119,448 KB
最終ジャッジ日時 2023-09-10 10:10:57
合計ジャッジ時間 14,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,732 KB
testcase_01 AC 92 ms
71,652 KB
testcase_02 AC 93 ms
71,868 KB
testcase_03 AC 151 ms
79,224 KB
testcase_04 AC 152 ms
81,824 KB
testcase_05 AC 150 ms
79,364 KB
testcase_06 AC 148 ms
81,660 KB
testcase_07 AC 151 ms
81,716 KB
testcase_08 AC 147 ms
81,568 KB
testcase_09 AC 149 ms
78,960 KB
testcase_10 AC 90 ms
71,916 KB
testcase_11 AC 90 ms
71,804 KB
testcase_12 AC 90 ms
71,808 KB
testcase_13 AC 90 ms
71,648 KB
testcase_14 AC 89 ms
71,864 KB
testcase_15 AC 90 ms
71,864 KB
testcase_16 AC 372 ms
111,508 KB
testcase_17 AC 388 ms
112,256 KB
testcase_18 AC 356 ms
116,588 KB
testcase_19 AC 548 ms
115,884 KB
testcase_20 AC 521 ms
110,944 KB
testcase_21 AC 528 ms
111,208 KB
testcase_22 AC 514 ms
119,448 KB
testcase_23 AC 575 ms
116,072 KB
testcase_24 AC 520 ms
115,924 KB
testcase_25 AC 601 ms
116,572 KB
testcase_26 AC 591 ms
116,368 KB
testcase_27 AC 585 ms
116,800 KB
testcase_28 AC 584 ms
116,508 KB
testcase_29 AC 592 ms
116,484 KB
testcase_30 AC 608 ms
116,304 KB
testcase_31 AC 623 ms
116,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
box = [[]for _ in range(m+1)]
color = [[]for _ in range(n+1)]
for _ in range(n):
  b, c = map(int, input().split())
  box[b].append(c)
  color[c].append(b)

boxused = [-1]*(m+1)
boxused[0]= 0
colorused = [-1]*(n+1)
colorused[0] = 0

from collections import deque

cnt = 0
for i in range(m+1):
  if boxused[i] == -1:
    d = deque()
    d.append(i)
    boxused[i] = 0
    while d:
      v = d.popleft()
      for x in box[v]:
        if colorused[x] == -1:
          colorused[x] = 0
          for y in color[x]:
            if boxused[y] == -1:
              boxused[y] = 0
              d.append(y)
              cnt += 1

print(cnt)
0