結果
問題 | No.1293 2種類の道路 |
ユーザー | tcltk |
提出日時 | 2020-11-21 02:50:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,080 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 46,108 KB |
最終ジャッジ日時 | 2024-07-23 14:21:33 |
合計ジャッジ時間 | 4,303 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
17,820 KB |
testcase_01 | AC | 29 ms
10,752 KB |
testcase_02 | AC | 29 ms
10,752 KB |
testcase_03 | AC | 29 ms
10,624 KB |
testcase_04 | AC | 34 ms
10,752 KB |
testcase_05 | AC | 29 ms
10,880 KB |
testcase_06 | AC | 30 ms
10,880 KB |
testcase_07 | AC | 28 ms
10,880 KB |
testcase_08 | AC | 41 ms
10,752 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 | -- | - |
ソースコード
#!/usr/bin/env python3 # from typing import * import io import sys # _INPUT = """\ # 4 2 1 # 1 2 # 2 3 # 2 4 # """ # sys.stdin = io.StringIO(_INPUT) def dfs_car(N, roads_car, pos, seen_car): seen_car[pos] = True for road in roads_car: if road[0] == pos and not seen_car[road[1]]: dfs_car(N, roads_car, road[1], seen_car) elif road[1] == pos and not seen_car[road[0]]: dfs_car(N, roads_car, road[0], seen_car) def dfs_walk(N, roads_walk, pos, seen_walk, seen_car_walk): seen_walk[pos] = True seen_car_walk[pos] = True for road in roads_walk: if road[0] == pos and not seen_walk[road[1]]: dfs_walk(N, roads_walk, road[1], seen_walk, seen_car_walk) elif road[1] == pos and not seen_walk[road[0]]: dfs_walk(N, roads_walk, road[0], seen_walk, seen_car_walk) # def solve(N: int, D: int, W: int, a: List[int], b: List[int], c: List[int], d: List[int]) -> int: def solve(N, roads_car, roads_walk): count = 0 seen_car_grand = [False] * N for pos in range(N): if seen_car_grand[pos]: continue seen_car = [False] * N dfs_car(N, roads_car, pos, seen_car) seen_car_walk = [seen for seen in seen_car] for pos1 in [i for i, x in enumerate(seen_car) if x]: seen_walk = [False] * N dfs_walk(N, roads_walk, pos1, seen_walk, seen_car_walk) n_car = len([1 for seen in seen_car if seen]) n_car_walk = len([1 for seen in seen_car_walk if seen]) count += n_car * (n_car_walk - 1) seen_car_grand = [seen_car_grand[i] or seen_car[i] for i in range(N)] return count def main(): N, D, W = map(int, input().split()) roads_car = [] roads_walk = [] for i in range(D): a, b = map(int, input().split()) roads_car.append((a - 1, b - 1)) for i in range(W): c, d = map(int, input().split()) roads_walk.append((c - 1, d - 1)) a1 = solve(N, roads_car, roads_walk) print(a1) if __name__ == '__main__': main()