結果

問題 No.1190 Points
ユーザー roarisroaris
提出日時 2020-08-22 14:45:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 109,572 KB
最終ジャッジ日時 2023-08-05 11:59:36
合計ジャッジ時間 9,661 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,728 KB
testcase_01 AC 95 ms
71,616 KB
testcase_02 AC 95 ms
71,420 KB
testcase_03 AC 305 ms
98,348 KB
testcase_04 AC 291 ms
95,080 KB
testcase_05 AC 291 ms
96,696 KB
testcase_06 AC 368 ms
102,144 KB
testcase_07 AC 376 ms
106,372 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 475 ms
109,572 KB
testcase_24 AC 462 ms
109,296 KB
testcase_25 AC 361 ms
102,332 KB
testcase_26 AC 261 ms
101,908 KB
testcase_27 AC 352 ms
102,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def bfs(sta):
    dist = [10**18]*(2*N)
    dist[2*sta] = 0
    q = deque([2*sta])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==10**18:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N, M, P = map(int, input().split())
s, g = map(int, input().split())
s -= 1
g -= 1
G = [[] for _ in range(2*N)]

for _ in range(N-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[2*u].append(2*v+1)
    G[2*u+1].append(2*v)
    G[2*v].append(2*u+1)
    G[2*v+1].append(2*u)

dist1 = bfs(s)
dist2 = bfs(g)
ans = []

for i in range(N):
    if P%2==0 and min(dist1[2*i]+dist2[2*i], dist1[2*i+1]+dist2[2*i+1])<=P:
        ans.append(i)
    elif P%2==1 and min(dist1[2*i]+dist2[2*i+1], dist1[2*i+1]+dist2[2*i])<=P:
        ans.append(i)

if len(ans)==0:
    print(-1)
    exit()
    
print(len(ans))

for ans_i in ans:
    print(ans_i+1)
0