結果
問題 |
No.1190 Points
|
ユーザー |
![]() |
提出日時 | 2022-02-09 22:46:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,585 bytes |
コンパイル時間 | 386 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 259,988 KB |
最終ジャッジ日時 | 2024-06-25 03:06:26 |
合計ジャッジ時間 | 24,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 3 |
ソースコード
import collections import heapq class Dijkstra: def __init__(self): self.e = collections.defaultdict(list) def add(self, u, v, d): self.e[u].append([v, d]) self.e[v].append([u, 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): """ :param s: 始点 :return: 始点から各点までの最短経路 """ 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 = map(int, input().split()) S,G = map(int, input().split()) D = Dijkstra() for _ in range(M): a,b = map(int, input().split()) D.add(a,-b,1) D.add(-a,b,1) SD = D.search(S) if P%2==1: G=-G GD = D.search(G) dis = SD[G] if dis==float('inf'): print(-1) exit() amari = (P-dis)//2 ANS = [] for i in range(1,N+1): if SD[i]+GD[i]<=P or SD[i]+GD[-i]<=P or SD[-i]+GD[i]<=P or SD[-i]+GD[-i]<=P or SD[i]<=amari or SD[-i]<=amari or GD[i]<=amari or GD[-i]<=amari: ANS.append(i) print(len(ANS)) for ans in ANS: print(ans)