結果
問題 | No.1190 Points |
ユーザー | ayaoni |
提出日時 | 2020-12-11 12:29:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,322 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 81,668 KB |
実行使用メモリ | 284,276 KB |
最終ジャッジ日時 | 2023-10-20 01:26:15 |
合計ジャッジ時間 | 41,418 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
55,480 KB |
testcase_01 | AC | 44 ms
55,480 KB |
testcase_02 | AC | 43 ms
55,480 KB |
testcase_03 | AC | 1,128 ms
192,804 KB |
testcase_04 | AC | 996 ms
181,828 KB |
testcase_05 | AC | 947 ms
174,932 KB |
testcase_06 | AC | 1,361 ms
244,324 KB |
testcase_07 | AC | 1,442 ms
245,976 KB |
testcase_08 | AC | 1,926 ms
279,568 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | AC | 1,547 ms
204,196 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 1,612 ms
187,168 KB |
testcase_14 | AC | 299 ms
160,332 KB |
testcase_15 | TLE | - |
testcase_16 | AC | 364 ms
103,304 KB |
testcase_17 | TLE | - |
testcase_18 | AC | 1,155 ms
141,144 KB |
testcase_19 | AC | 320 ms
166,344 KB |
testcase_20 | AC | 1,554 ms
165,132 KB |
testcase_21 | AC | 603 ms
142,872 KB |
testcase_22 | AC | 424 ms
188,644 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | AC | 1,555 ms
254,752 KB |
testcase_26 | AC | 638 ms
221,880 KB |
testcase_27 | AC | 1,636 ms
261,144 KB |
ソースコード
import sys,collections,heapq sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) class Dijkstra: def __init__(self): self.e = collections.defaultdict(list) def add(self, u, v, d, directed=False): if directed is False: # 無向グラフの場合 self.e[u].append([v, d]) self.e[v].append([u, d]) else: # 有向グラフの場合 self.e[u].append([v, d]) def delete(self, u, v): self.e[u] = [_ for _ in self.e[u] if _[0] != v] self.e[v] = [_ for _ in self.e[v] if _[0] != u] def search(self, s): # sから各頂点までの最短距離 d = collections.defaultdict(lambda: float('inf')) d[s] = 0 q = [] heapq.heappush(q, (0, s)) v = collections.defaultdict(bool) while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True for uv, ud in self.e[u]: if v[uv]: continue vd = k + ud if d[uv] > vd: d[uv] = vd heapq.heappush(q, (vd, uv)) return d N,M,P = MI() S,G = MI() Di = Dijkstra() for _ in range(M): u,v = MI() Di.add((u,0),(v,1),1,directed=False) Di.add((u,1),(v,0),1,directed=False) dist_S = Di.search((S,0)) dist_G = Di.search((G,0)) ANS = [] for i in range(1,N+1): if P % 2 == 0: d0 = dist_S[(i,0)]+dist_G[(i,0)] d1 = dist_S[(i,1)]+dist_G[(i,1)] if (d0 != float('inf') and d0 <= P) or (d1 != float('inf') and d1 <= P): ANS.append(i) else: d0 = dist_S[(i,0)]+dist_G[(i,1)] d1 = dist_S[(i,1)]+dist_G[(i,0)] if (d0 != float('inf') and d0 <= P) or (d1 != float('inf') and d1 <= P): ANS.append(i) if ANS: print(len(ANS)) print(*ANS,sep='\n') else: print(-1) # bfsの方が速く解ける