結果

問題 No.1190 Points
ユーザー ayaoniayaoni
提出日時 2020-12-11 12:43:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 144,784 KB
最終ジャッジ日時 2023-10-20 01:26:56
合計ジャッジ時間 14,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,540 KB
testcase_01 AC 42 ms
55,540 KB
testcase_02 AC 41 ms
55,540 KB
testcase_03 AC 480 ms
119,660 KB
testcase_04 AC 401 ms
113,252 KB
testcase_05 AC 392 ms
115,580 KB
testcase_06 AC 583 ms
128,720 KB
testcase_07 AC 604 ms
138,500 KB
testcase_08 AC 543 ms
144,784 KB
testcase_09 AC 620 ms
137,112 KB
testcase_10 AC 542 ms
144,248 KB
testcase_11 AC 449 ms
120,300 KB
testcase_12 AC 610 ms
138,088 KB
testcase_13 AC 483 ms
112,448 KB
testcase_14 AC 173 ms
100,660 KB
testcase_15 AC 790 ms
138,820 KB
testcase_16 AC 135 ms
85,088 KB
testcase_17 AC 730 ms
135,352 KB
testcase_18 AC 347 ms
100,324 KB
testcase_19 AC 181 ms
111,968 KB
testcase_20 AC 465 ms
109,024 KB
testcase_21 AC 240 ms
101,120 KB
testcase_22 AC 245 ms
118,676 KB
testcase_23 AC 908 ms
142,712 KB
testcase_24 AC 826 ms
142,528 KB
testcase_25 AC 640 ms
131,108 KB
testcase_26 AC 373 ms
131,060 KB
testcase_27 AC 599 ms
131,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,collections,heapq
from collections import deque
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())


N,M,P = MI()
S,G = MI()

Graph = [[[] for _ in range(2)] for _ in range(N+1)]
for _ in range(M):
    u,v = MI()
    Graph[u][0].append((v,1))
    Graph[v][0].append((u,1))
    Graph[u][1].append((v,0))
    Graph[v][1].append((u,0))

inf = 10**18
dist_S = [[inf]*2 for _ in range(N+1)]
dist_G = [[inf]*2 for _ in range(N+1)]
dist_S[S][0] = 0
dist_G[G][0] = 0
deq_S = deque([(S,0)])
deq_G = deque([(G,0)])
while deq_S:
    u,r = deq_S.pop()
    for v,s in Graph[u][r]:
        if dist_S[v][s] == inf:
            dist_S[v][s] = dist_S[u][r]+1
            deq_S.appendleft((v,s))
while deq_G:
    u,r = deq_G.pop()
    for v,s in Graph[u][r]:
        if dist_G[v][s] == inf:
            dist_G[v][s] = dist_G[u][r]+1
            deq_G.appendleft((v,s))

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 != inf and d0 <= P) or (d1 != 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 != inf and d0 <= P) or (d1 != inf and d1 <= P):
            ANS.append(i)

if ANS:
    print(len(ANS))
    print(*ANS,sep='\n')
else:
    print(-1)

# DijkstraだとTLE
0