結果
| 問題 |
No.1390 Get together
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-25 10:46:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 564 ms / 2,000 ms |
| コード長 | 667 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 82,136 KB |
| 実行使用メモリ | 116,284 KB |
| 最終ジャッジ日時 | 2024-06-28 01:36:46 |
| 合計ジャッジ時間 | 12,154 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
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)