提出 #66747245


ソースコード 拡げる

from sys import stdin
input = stdin.readline


def solve():
    node_size, edge_count = map(int, input().split())
    graph = [[] for _ in range(node_size + 1)]
    for _ in range(edge_count):
        one, two, cost = map(int, input().split())
        graph[one].append((two, cost))

    stack = [(1, 0)]
    seen = set(stack)
    result = float('inf')
    while stack:
        node, cost = stack.pop()
        if node == node_size:
            result = min(result, cost)

        for other, other_cost in graph[node]:
            new_cost = cost ^ other_cost
            if (other, new_cost) not in seen:
                seen.add((other, new_cost))
                stack.append((other, new_cost))


    if result == float('inf'):
        result = -1

    return result


print(solve())

提出情報

提出日時
問題 D - XOR Shortest Walk
ユーザ sleepingonee
言語 Python (PyPy 3.10-v7.3.12)
得点 400
コード長 820 Byte
結果 AC
実行時間 273 ms
メモリ 183436 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 33
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 54 ms 76304 KiB
hand_02.txt AC 54 ms 76464 KiB
hand_03.txt AC 54 ms 76396 KiB
hand_04.txt AC 54 ms 76660 KiB
hand_05.txt AC 54 ms 76228 KiB
hand_06.txt AC 54 ms 76468 KiB
hand_07.txt AC 54 ms 76432 KiB
hand_08.txt AC 54 ms 76468 KiB
random_01.txt AC 54 ms 76400 KiB
random_02.txt AC 55 ms 76808 KiB
random_03.txt AC 54 ms 76492 KiB
random_04.txt AC 55 ms 76540 KiB
random_05.txt AC 54 ms 76512 KiB
random_06.txt AC 54 ms 76380 KiB
random_07.txt AC 54 ms 76524 KiB
random_08.txt AC 55 ms 76556 KiB
random_09.txt AC 53 ms 76556 KiB
random_10.txt AC 56 ms 76612 KiB
random_11.txt AC 53 ms 76336 KiB
random_12.txt AC 56 ms 76448 KiB
random_13.txt AC 101 ms 89728 KiB
random_14.txt AC 141 ms 109620 KiB
random_15.txt AC 78 ms 82356 KiB
random_16.txt AC 54 ms 76488 KiB
random_17.txt AC 57 ms 76604 KiB
random_18.txt AC 56 ms 76464 KiB
random_19.txt AC 273 ms 183436 KiB
random_20.txt AC 204 ms 131432 KiB
random_21.txt AC 208 ms 134672 KiB
random_22.txt AC 209 ms 135040 KiB
sample_01.txt AC 54 ms 76536 KiB
sample_02.txt AC 54 ms 76480 KiB
sample_03.txt AC 54 ms 76384 KiB