結果
問題 | No.1602 With Animals into Institute 2 |
ユーザー | shotoyoo |
提出日時 | 2021-07-03 17:54:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,080 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 318,272 KB |
最終ジャッジ日時 | 2024-07-02 02:09:49 |
合計ジャッジ時間 | 7,609 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
62,208 KB |
testcase_01 | AC | 59 ms
62,464 KB |
testcase_02 | WA | - |
testcase_03 | AC | 199 ms
81,792 KB |
testcase_04 | AC | 204 ms
81,664 KB |
testcase_05 | WA | - |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
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 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) class UF: # unionfind def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n def check(self): return [self.root(i) for i in range(self.n)] def root(self, i): inter = set() while self.parent[i]!=i: inter.add(i) i = self.parent[i] r = i for i in inter: self.parent[i] = r return r def connect(self, i, j): # 繋いだかどうかを返す ri = self.root(i) rj = self.root(j) if ri==rj: return False if depth[rj]<depth[ri]: self.parent[ri] = rj self.size[rj] += self.size[ri] else: self.parent[rj] = ri self.size[ri] += self.size[rj] return True # グラフの読み込み・重みあり inf = 10**16 n,m,k = map(int, input().split()) ns = [[] for _ in range(n)] ans = [-1]*n h = [] q = [inf]*n parent = list(range(n)) uf = UF(n) d = [-1]*n l = [-1]*n es = [] for e in range(m): u,v,c,x = input().split() u = int(u) v = int(v) c = int(c) x = int(x, 2) u -= 1 v -= 1 ns[u].append((c,x,e,v)) ns[v].append((c,x,e,u)) es.append((u,v,c,x)) ### ダイクストラ dijkstra _val = 1<<20 def t2i(*vs): n = len(vs)+1 nvs = [1] val = 1 for v in vs[::-1]: val *= v nvs.append(val) vs = nvs[::-1] tos = "def to(%s):\n" % (",".join([f"v{i}" for i in range(n)])) tos += " val = 0\n" for i,v in enumerate(vs): tos += f" val += {v} * v{i}\n" tos += " return val" frms = f"def frm(val):\n" for i in range(n-1): frms += f" v{i},val = divmod(val, {vs[i]})\n" frms += " return %s" % ((", ".join([f"v{i}" for i in range(n-1)]) + ", val")) return tos, frms tos, frms = t2i(1<<k, 1<<20) exec(tos) exec(frms) ### ダイクストラ dijkstra _val = 1<<20 inf = 10**15 # def to(d,u): # return d*_val+u # def frm(val): # return divmod(val,_val) def dijkstra(start,ns): from heapq import heappop as hpp, heappush as hp vals = [[] for _ in range(n)] ls = [[] for _ in range(n)] h = [to(0, 0, start)] # (距離, ノード番号) vals[start].append(0) # order = [] while h: val, l, u = frm(hpp(h)) if len(vals[u])>=num: continue vals[u].append(val) ls[u].append(l) # order.append(u) for d,x,e,v in ns[u]: # if vals[v]>val+d: # vals[v] = val+d hp(h, to(val+d, l^x, v)) return vals, ls num = 10 vals, ls = dijkstra(n-1, ns) ans = [inf]*(n-1) for v in range(n-1): for i in range(len(ls[v])): if ls[v][i]!=0: ans[v] = min(ans[v], vals[v][i]) if ans[v]==inf: ans[v] = -1 write("\n".join(map(str, ans)))