結果
問題 | No.1690 Power Grid |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 23:14:34 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,743 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,256 KB |
実行使用メモリ | 85,376 KB |
最終ジャッジ日時 | 2024-07-05 11:30:55 |
合計ジャッジ時間 | 26,621 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
63,436 KB |
testcase_01 | AC | 43 ms
55,260 KB |
testcase_02 | AC | 43 ms
55,692 KB |
testcase_03 | AC | 43 ms
56,284 KB |
testcase_04 | AC | 42 ms
55,360 KB |
testcase_05 | AC | 42 ms
55,644 KB |
testcase_06 | AC | 2,808 ms
77,132 KB |
testcase_07 | AC | 2,794 ms
77,364 KB |
testcase_08 | AC | 2,783 ms
77,144 KB |
testcase_09 | AC | 2,795 ms
76,940 KB |
testcase_10 | AC | 70 ms
71,924 KB |
testcase_11 | AC | 106 ms
77,036 KB |
testcase_12 | AC | 42 ms
54,696 KB |
testcase_13 | AC | 80 ms
76,928 KB |
testcase_14 | AC | 417 ms
77,176 KB |
testcase_15 | AC | 63 ms
70,056 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 1,776 ms
77,412 KB |
testcase_18 | AC | 845 ms
77,944 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
import sys from operator import itemgetter from collections import defaultdict, deque import heapq import bisect from itertools import combinations stdin=sys.stdin sys.setrecursionlimit(10 ** 8) ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() Yp=lambda:print('Yes') Np=lambda:print('No') inf = float('inf') eps = 1e-9 sortkey = itemgetter(0) ############################################################### N, M, K = lp() A = lp() edges = [[inf for _ in range(N)] for _ in range(N)] for i in range(N): edges[i][i] = 0 for _ in range(M): x, y, z = lp() x -= 1; y -= 1 edges[x][y] = z edges[y][x] = z for s in range(N): for g in range(N): for mid in range(N): if s == mid or g == mid: continue dist = min(edges[s][g], edges[s][mid] + edges[mid][g]) edges[s][g] = dist citys = [i for i in range(N)] ans = inf for v in combinations(citys,K): temp = 0 candidate = [0 for _ in range(N)] for city in v: temp += A[city] candidate[city] = 1 for start in v: res = temp build = 1 complete = [0 for _ in range(N)] finish = [start] complete[start] = 1 while build < K: dist = inf nex = -1 for now in finish: for ne in range(N): if candidate[ne] == 1 and complete[ne] == 0 and dist > edges[now][ne]: nex = ne dist = edges[now][ne] res += dist complete[nex] = 1 finish.append(nex) build += 1 ans = min(ans, res) print(ans)