結果

問題 No.1190 Points
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-18 15:38:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 544 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 119,908 KB
最終ジャッジ日時 2023-09-04 10:18:08
合計ジャッジ時間 13,734 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,564 KB
testcase_01 AC 100 ms
71,928 KB
testcase_02 AC 101 ms
71,928 KB
testcase_03 AC 365 ms
101,892 KB
testcase_04 AC 342 ms
97,984 KB
testcase_05 AC 328 ms
99,908 KB
testcase_06 AC 399 ms
104,080 KB
testcase_07 AC 424 ms
110,528 KB
testcase_08 AC 419 ms
119,712 KB
testcase_09 AC 489 ms
118,240 KB
testcase_10 AC 436 ms
119,892 KB
testcase_11 AC 391 ms
104,048 KB
testcase_12 AC 469 ms
116,756 KB
testcase_13 AC 416 ms
105,176 KB
testcase_14 AC 179 ms
90,044 KB
testcase_15 AC 519 ms
119,496 KB
testcase_16 AC 181 ms
84,464 KB
testcase_17 AC 485 ms
111,460 KB
testcase_18 AC 306 ms
92,736 KB
testcase_19 AC 168 ms
90,180 KB
testcase_20 AC 369 ms
97,948 KB
testcase_21 AC 240 ms
92,232 KB
testcase_22 AC 215 ms
97,596 KB
testcase_23 AC 544 ms
117,544 KB
testcase_24 AC 520 ms
119,908 KB
testcase_25 AC 395 ms
107,304 KB
testcase_26 AC 269 ms
104,796 KB
testcase_27 AC 397 ms
107,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,p=map(int,input().split())
s,t=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for u,v in uv:
  u,v=u-1,v-1
  g[u].append(v)
  g[v].append(u)
s,t=s-1,t-1
inf=float('inf')
fromsev=[inf]*n
fromtev=[inf]*n
fromsod=[inf]*n
fromtod=[inf]*n
from collections import deque
todo=deque([[s,0]])
fromsev[s]=0
while todo:
  v,d=todo.popleft()
  for nv in g[v]:
    if (d+1)%2==0:
      if fromsev[nv]>d+1:
        fromsev[nv]=d+1
        todo.append([nv,d+1])
    else:
      if fromsod[nv]>d+1:
        fromsod[nv]=d+1
        todo.append([nv,d+1])
todo=deque([[t,0]])
fromtev[t]=0
while todo:
  v,d=todo.popleft()
  for nv in g[v]:
    if (d+1)%2==0:
      if fromtev[nv]>d+1:
        fromtev[nv]=d+1
        todo.append([nv,d+1])
    else:
      if fromtod[nv]>d+1:
        fromtod[nv]=d+1
        todo.append([nv,d+1])
ans=[]
if p%2==0:
  for i in range(n):
    if fromsev[i]+fromtev[i]<=p:
      ans.append(i+1)
    elif fromsod[i]+fromtod[i]<=p:
      ans.append(i+1)
else:
  for i in range(n):
    if fromsev[i]+fromtod[i]<=p:
      ans.append(i+1)
    elif fromsod[i]+fromtev[i]<=p:
      ans.append(i+1)
if ans:
  print(len(ans))
  print(*ans,sep='\n')
else:
  print(-1)
0