結果

問題 No.1190 Points
ユーザー chineristACchineristAC
提出日時 2020-08-22 13:52:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,775 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 149,900 KB
最終ジャッジ日時 2024-04-23 08:18:17
合計ジャッジ時間 15,023 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,436 KB
testcase_01 AC 38 ms
54,856 KB
testcase_02 AC 38 ms
53,452 KB
testcase_03 AC 501 ms
123,376 KB
testcase_04 AC 426 ms
117,168 KB
testcase_05 WA -
testcase_06 AC 564 ms
134,332 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 721 ms
147,708 KB
testcase_10 AC 673 ms
144,864 KB
testcase_11 WA -
testcase_12 AC 682 ms
144,780 KB
testcase_13 AC 611 ms
123,768 KB
testcase_14 AC 125 ms
95,708 KB
testcase_15 AC 876 ms
148,200 KB
testcase_16 AC 169 ms
87,776 KB
testcase_17 AC 795 ms
141,256 KB
testcase_18 AC 454 ms
117,292 KB
testcase_19 AC 97 ms
88,836 KB
testcase_20 AC 541 ms
123,904 KB
testcase_21 AC 245 ms
100,824 KB
testcase_22 AC 160 ms
108,824 KB
testcase_23 AC 904 ms
149,900 KB
testcase_24 AC 899 ms
149,404 KB
testcase_25 AC 564 ms
140,376 KB
testcase_26 AC 235 ms
128,748 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Dijkstra():
    class Edge():
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        self.G = [[] for i in range(V)]
        self._E = 0
        self._V = V

    @property
    def E(self):
        return self._E

    @property
    def V(self):
        return self._V

    def add(self, _from, _to, _cost):
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        import heapq
        que = []
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost
                    heapq.heappush(que, (d[e.to], e.to))
        return d

import sys

input=sys.stdin.readline

N,M,P=map(int,input().split())
S,G=map(int,input().split())
S-=1;G-=1

graph=Dijkstra(2*N)
for _ in range(M):
    u,v=map(int,input().split())
    u-=1;v-=1
    graph.add(2*u,2*v+1,1)
    graph.add(2*u+1,2*v,1)
    graph.add(2*v,2*u+1,1)
    graph.add(2*v+1,2*u,1)

start=graph.shortest_path(2*S)
goal=graph.shortest_path(2*G)

res=[]
for i in range(N):
    if P%2:
        d1=start[2*i]
        d2=goal[2*i+1]
        d3=start[2*i+1]
        d4=goal[2*i]
        if d1+d2<=P or d3+d4<=P:
            res.append(i)
    else:
        d1=start[2*i]
        d2=goal[2*i+1]
        d3=start[2*i+1]
        d4=goal[2*i]
        if d1+d4<=P or d2+d4<=P:
            res.append(i)

res.sort()

if res:
    print(len(res))
    for v in res:
        print(v+1)
else:
    print(-1)
0