結果
問題 | No.1293 2種類の道路 |
ユーザー | c-yan |
提出日時 | 2020-11-21 00:01:08 |
言語 | PyPy3 (7.3.13) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,091 bytes |
コンパイル時間 | 559 ms |
コンパイル使用メモリ | 87,104 KB |
実行使用メモリ | 291,000 KB |
最終ジャッジ日時 | 2023-09-30 20:16:30 |
合計ジャッジ時間 | 5,501 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
78,240 KB |
testcase_01 | AC | 70 ms
71,324 KB |
testcase_02 | AC | 70 ms
71,172 KB |
testcase_03 | AC | 69 ms
71,324 KB |
testcase_04 | AC | 70 ms
71,088 KB |
testcase_05 | AC | 68 ms
71,196 KB |
testcase_06 | AC | 68 ms
71,152 KB |
testcase_07 | AC | 69 ms
71,388 KB |
testcase_08 | AC | 70 ms
71,172 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()) parent0 = [-1] * N for _ in range(D): a, b = map(lambda x: int(x) - 1, readline().split()) unite(parent0, a, b) parent1 = [-1] * N for _ in range(W): c, d = map(lambda x: int(x) - 1, readline().split()) unite(parent1, c, d) ss0 = {} xs = [i for i in range(N) if parent0[i] < 0] for x in xs: ss0[x] = set() for i in range(N): ss0[find(parent0, i)].add(i) ss1 = {} ys = [i for i in range(N) if parent1[i] < 0] for y in ys: ss1[y] = set() for i in range(N): ss1[find(parent1, i)].add(i) result = 0 for x in xs: t = ss0[x].copy() for z in ss0[x]: t |= ss1[find(parent1, z)] result += len(ss0[x]) * (len(t) - 1) print(result)