Submission #66774120


Source Code Expand

Copy
N, M = map(int, input().split())
G, W = [[] for _ in range(N)], [[0] * N for _ in range(N)]
for _ in range(M):
a, b, w = map(int, input().split())
G[a - 1].append(b - 1)
W[a - 1][b - 1] = w
import sys
sys.setrecursionlimit(10**7)
def min_xor_walk(adj, W):
N = len(adj)
dist = [None] * N
dist[0] = 0
basis = []
def insert_basis(x):
for b in basis:
x = min(x, x ^ b)
if x:
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
N, M = map(int, input().split())
G, W = [[] for _ in range(N)], [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, w = map(int, input().split())
    G[a - 1].append(b - 1)
    W[a - 1][b - 1] = w

import sys
sys.setrecursionlimit(10**7)

def min_xor_walk(adj, W):
    N = len(adj)
    dist = [None] * N
    dist[0] = 0

    basis = []

    def insert_basis(x):
        for b in basis:
            x = min(x, x ^ b)
        if x:
            basis.append(x)
            basis.sort(reverse=True)

    def dfs(u):
        for v in adj[u]:
            x = dist[u] ^ W[u][v]
            if dist[v] is None:
                dist[v] = x
                dfs(v)
            else:
                insert_basis(x ^ dist[v])

    dfs(0)

    if dist[N-1] is None:
        return None

    res = dist[N-1]
    for b in basis:
        res = min(res, res ^ b)
    return res

ans = min_xor_walk(G, W)
if ans is None:
    print(-1)
else:
    print(ans)

Submission Info

Submission Time
Task D - XOR Shortest Walk
User ttmn
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 989 Byte
Status WA
Exec Time 82 ms
Memory 81648 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 31
WA × 2
Set Name Test Cases
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
Case Name Status Exec Time Memory
hand_01.txt AC 67 ms 76524 KiB
hand_02.txt AC 67 ms 76452 KiB
hand_03.txt AC 67 ms 76524 KiB
hand_04.txt AC 68 ms 76528 KiB
hand_05.txt AC 66 ms 76876 KiB
hand_06.txt WA 67 ms 76536 KiB
hand_07.txt WA 65 ms 76540 KiB
hand_08.txt AC 66 ms 76632 KiB
random_01.txt AC 64 ms 76688 KiB
random_02.txt AC 72 ms 76868 KiB
random_03.txt AC 66 ms 76668 KiB
random_04.txt AC 71 ms 76884 KiB
random_05.txt AC 67 ms 76624 KiB
random_06.txt AC 70 ms 76580 KiB
random_07.txt AC 68 ms 76564 KiB
random_08.txt AC 74 ms 77036 KiB
random_09.txt AC 68 ms 76532 KiB
random_10.txt AC 79 ms 81468 KiB
random_11.txt AC 65 ms 76512 KiB
random_12.txt AC 72 ms 77252 KiB
random_13.txt AC 73 ms 80868 KiB
random_14.txt AC 75 ms 81040 KiB
random_15.txt AC 72 ms 81188 KiB
random_16.txt AC 69 ms 76880 KiB
random_17.txt AC 80 ms 81648 KiB
random_18.txt AC 80 ms 81624 KiB
random_19.txt AC 81 ms 81632 KiB
random_20.txt AC 82 ms 80972 KiB
random_21.txt AC 81 ms 81252 KiB
random_22.txt AC 82 ms 80948 KiB
sample_01.txt AC 67 ms 76528 KiB
sample_02.txt AC 69 ms 76688 KiB
sample_03.txt AC 65 ms 76696 KiB


2025-06-16 (Mon)
14:19:58 +09:00