32422023-02-23 11:22:4912BotiTom és Jerry2 (60)python3Time limit exceeded 17/60479ms25532 KiB
N, M, tstart, db, E = map(int, input().split())
tstart -= 1
E -= 1
ns = [[] for _ in range(N)]
for _ in range(M):
    a, b, s = map(int, input().split())
    a -= 1
    b -= 1
    ns[a].append((b, s))
    ns[b].append((a, s))
treach = [1e6] * N
treach[tstart] = 0

op = {tstart}
cl = set()
steps = 1
while len(op) > 0:
    nextop = set()
    for n in op:
        for (ne, s) in ns[n]:
            if s == 2 and ne not in cl and ne not in op:
                nextop.add(ne)
                treach[ne] = steps
    cl = cl.union(op)
    op = nextop
    steps += 1


def doit(jstart):
    op = {jstart}
    cl = set()
    obs = set()
    while len(op) > 0:
        newop = set()
        for n in op:
            for (ne, _) in ns[n]:
                if ne in op or ne in cl:
                    continue
                if ne == E:
                    return 0
                if treach[ne] > steps:
                    newop.add(ne)
                else:
                    obs.add(ne)
        cl = cl.union(op)
        op = newop
        if len(obs) >= 2:
            op = op.union(obs)
            obs = set()
    return next(iter(obs)) + 1


jstarts = [int(x) - 1 for x in input().split()]
steps = 1
for jstart in jstarts:
    print(doit(jstart))
SubtaskSumTestVerdictTimeMemory
base17/60
1Accepted0/018ms12052 KiB
2Time limit exceeded0/0470ms9152 KiB
3Accepted2/217ms12404 KiB
4Accepted2/217ms12560 KiB
5Accepted2/218ms12940 KiB
6Wrong answer0/318ms12872 KiB
7Accepted2/220ms13128 KiB
8Wrong answer0/235ms13624 KiB
9Wrong answer0/227ms13536 KiB
10Wrong answer0/356ms13976 KiB
11Wrong answer0/339ms14308 KiB
12Accepted3/3158ms15504 KiB
13Accepted3/3254ms17428 KiB
14Accepted3/3363ms18516 KiB
15Time limit exceeded0/3467ms9132 KiB
16Time limit exceeded0/3462ms9996 KiB
17Time limit exceeded0/3474ms10432 KiB
18Time limit exceeded0/3477ms13476 KiB
19Time limit exceeded0/4446ms19188 KiB
20Time limit exceeded0/4460ms25532 KiB
21Time limit exceeded0/5479ms15984 KiB
22Time limit exceeded0/5470ms16768 KiB