結果

問題 No.1190 Points
ユーザー chineristACchineristAC
提出日時 2020-08-22 13:55:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 982 ms / 2,000 ms
コード長 1,775 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 81,900 KB
実行使用メモリ 150,028 KB
最終ジャッジ日時 2024-04-23 08:21:40
合計ジャッジ時間 15,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,312 KB
testcase_01 AC 34 ms
53,072 KB
testcase_02 AC 35 ms
54,516 KB
testcase_03 AC 551 ms
123,284 KB
testcase_04 AC 468 ms
116,952 KB
testcase_05 AC 429 ms
115,776 KB
testcase_06 AC 589 ms
134,468 KB
testcase_07 AC 665 ms
140,384 KB
testcase_08 AC 675 ms
144,352 KB
testcase_09 AC 758 ms
147,580 KB
testcase_10 AC 703 ms
144,864 KB
testcase_11 AC 587 ms
129,144 KB
testcase_12 AC 704 ms
144,520 KB
testcase_13 AC 625 ms
123,644 KB
testcase_14 AC 128 ms
95,596 KB
testcase_15 AC 913 ms
148,196 KB
testcase_16 AC 186 ms
87,640 KB
testcase_17 AC 838 ms
141,264 KB
testcase_18 AC 480 ms
117,288 KB
testcase_19 AC 108 ms
88,656 KB
testcase_20 AC 574 ms
123,904 KB
testcase_21 AC 259 ms
100,364 KB
testcase_22 AC 169 ms
108,760 KB
testcase_23 AC 970 ms
150,028 KB
testcase_24 AC 982 ms
149,540 KB
testcase_25 AC 597 ms
140,368 KB
testcase_26 AC 252 ms
129,104 KB
testcase_27 AC 641 ms
141,056 KB
権限があれば一括ダウンロードができます

ソースコード

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+d3<=P:
            res.append(i)

res.sort()

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