結果
問題 | No.1690 Power Grid |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 23:05:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,744 bytes |
コンパイル時間 | 510 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 78,080 KB |
最終ジャッジ日時 | 2024-07-05 11:14:13 |
合計ジャッジ時間 | 29,624 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,528 KB |
testcase_01 | AC | 40 ms
54,656 KB |
testcase_02 | AC | 40 ms
54,912 KB |
testcase_03 | AC | 44 ms
54,016 KB |
testcase_04 | AC | 40 ms
54,144 KB |
testcase_05 | AC | 39 ms
54,272 KB |
testcase_06 | AC | 2,839 ms
77,952 KB |
testcase_07 | AC | 2,857 ms
77,440 KB |
testcase_08 | AC | 2,855 ms
77,440 KB |
testcase_09 | AC | 2,840 ms
77,696 KB |
testcase_10 | AC | 72 ms
72,064 KB |
testcase_11 | AC | 107 ms
76,928 KB |
testcase_12 | AC | 41 ms
54,656 KB |
testcase_13 | AC | 90 ms
77,056 KB |
testcase_14 | AC | 408 ms
77,056 KB |
testcase_15 | AC | 66 ms
69,504 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 1,710 ms
76,800 KB |
testcase_18 | AC | 716 ms
77,440 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | AC | 60 ms
66,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 86 ms
76,800 KB |
testcase_24 | AC | 455 ms
78,080 KB |
testcase_25 | AC | 186 ms
77,824 KB |
testcase_26 | AC | 108 ms
77,056 KB |
testcase_27 | AC | 41 ms
54,528 KB |
ソースコード
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)] complete[start] = 1 while build < K: dist = inf nex = -1 for now in range(N): if complete[now] == 1: 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 build += 1 ans = min(ans, res) print(ans)