結果
問題 | No.1390 Get together |
ユーザー | kojihashimoto-kobe |
提出日時 | 2021-03-25 16:38:57 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 736 bytes |
コンパイル時間 | 468 ms |
コンパイル使用メモリ | 10,820 KB |
実行使用メモリ | 62,420 KB |
最終ジャッジ日時 | 2023-08-18 00:57:23 |
合計ジャッジ時間 | 5,443 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
13,088 KB |
testcase_01 | AC | 19 ms
8,444 KB |
testcase_02 | AC | 18 ms
8,496 KB |
testcase_03 | AC | 36 ms
9,620 KB |
testcase_04 | AC | 34 ms
9,520 KB |
testcase_05 | AC | 36 ms
9,640 KB |
testcase_06 | AC | 33 ms
9,436 KB |
testcase_07 | AC | 33 ms
9,524 KB |
testcase_08 | AC | 34 ms
9,496 KB |
testcase_09 | AC | 39 ms
9,688 KB |
testcase_10 | AC | 18 ms
8,612 KB |
testcase_11 | AC | 18 ms
8,464 KB |
testcase_12 | AC | 18 ms
8,432 KB |
testcase_13 | AC | 19 ms
8,616 KB |
testcase_14 | AC | 19 ms
8,536 KB |
testcase_15 | AC | 18 ms
8,500 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
n, m = map(int, input().split()) from collections import deque #色iのスライムがどの箱に入っているかを管理 color = [[] for _ in range(n+1)] #箱iにどの色のスライムが入っているかを管理 box = [[] for _ in range(m+1)] for i in range(n): b, c = map(int, input().split()) box[b].append(c) color[c].append(b) #アクセス済みの箱を管理 dist = [-1] * (m+1) dist[0] = 0 ans = 0 for i in range(m+1): if dist[i] == -1: dist[i] = 0 d = deque() d.append(i) while d: v = d.popleft() for j in box[v]: for k in color[j]: if dist[k] != -1: continue dist[k] = dist[v] + 1 d.append(k) ans += 1 print(ans)