結果
問題 | No.1293 2種類の道路 |
ユーザー | c-yan |
提出日時 | 2020-11-21 00:14:36 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,091 bytes |
コンパイル時間 | 1,027 ms |
コンパイル使用メモリ | 86,696 KB |
実行使用メモリ | 71,436 KB |
最終ジャッジ日時 | 2023-09-30 20:20:45 |
合計ジャッジ時間 | 6,563 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,116 KB |
testcase_01 | AC | 76 ms
71,184 KB |
testcase_02 | AC | 75 ms
71,260 KB |
testcase_03 | AC | 78 ms
71,436 KB |
testcase_04 | AC | 75 ms
71,060 KB |
testcase_05 | AC | 74 ms
71,232 KB |
testcase_06 | AC | 74 ms
71,228 KB |
testcase_07 | AC | 78 ms
71,324 KB |
testcase_08 | AC | 74 ms
70,924 KB |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
ソースコード
from sys import setrecursionlimit, stdin def find(parent, i): t = parent[i] if t < 0: return i t = find(parent, t) parent[i] = t return t def unite(parent, i, j): i = find(parent, i) j = find(parent, j) if i == j: return parent[j] += parent[i] parent[i] = j readline = stdin.readline setrecursionlimit(10 ** 6) N, D, W = map(int, readline().split()) car = [-1] * N for _ in range(D): a, b = map(lambda x: int(x) - 1, readline().split()) unite(car, a, b) walking = [-1] * N for _ in range(W): c, d = map(lambda x: int(x) - 1, readline().split()) unite(walking, c, d) ss0 = {} xs = [i for i in range(N) if car[i] < 0] for x in xs: ss0[x] = set() for i in range(N): ss0[find(car, i)].add(i) ss1 = {} ys = [i for i in range(N) if walking[i] < 0] for y in ys: ss1[y] = set() for i in range(N): ss1[find(walking, i)].add(i) result = 0 for x in xs: t = ss0[x].copy() for i in set(find(walking, z) for z in ss0[x]): t |= ss1[i] result += len(ss0[x]) * (len(t) - 1) print(result)