Submission #66745186


Source Code Expand

Copy
import sys
sys.setrecursionlimit(10 ** 8)
N, M = map(int, input().split())
graph = [[] for _ in range(N + 1)]
for _ in range(M):
a, b, w = map(int, input().split())
graph[a].append((b, w))
dist = [-1] * (N + 1)
basis = []
def insert_basis(x):
for b in basis:
x = min(x, x ^ b)
if x != 0:
basis.append(x)
basis.sort(reverse=True)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys

sys.setrecursionlimit(10 ** 8)

N, M = map(int, input().split())
graph = [[] for _ in range(N + 1)]

for _ in range(M):
    a, b, w = map(int, input().split())
    graph[a].append((b, w))

dist = [-1] * (N + 1)
basis = []


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


def dfs(v, xor_val):
    dist[v] = xor_val
    for to, w in graph[v]:
        next_xor = xor_val ^ w
        if dist[to] == -1:
            dfs(to, next_xor)
        else:
            insert_basis(dist[to] ^ next_xor)


dfs(1, 0)

if dist[N] == -1:
    print(-1)
else:
    ans = dist[N]
    for b in basis:
        ans = min(ans, ans ^ b)
    print(ans)

Submission Info

Submission Time
Task D - XOR Shortest Walk
User bubbleman
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 773 Byte
Status WA
Exec Time 71 ms
Memory 81504 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 30
WA × 3
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 59 ms 76516 KiB
hand_02.txt AC 60 ms 76308 KiB
hand_03.txt AC 58 ms 76784 KiB
hand_04.txt AC 59 ms 76772 KiB
hand_05.txt AC 59 ms 76548 KiB
hand_06.txt WA 60 ms 76436 KiB
hand_07.txt WA 58 ms 76344 KiB
hand_08.txt WA 60 ms 76716 KiB
random_01.txt AC 60 ms 76388 KiB
random_02.txt AC 66 ms 76808 KiB
random_03.txt AC 60 ms 76256 KiB
random_04.txt AC 63 ms 76656 KiB
random_05.txt AC 59 ms 76536 KiB
random_06.txt AC 61 ms 76828 KiB
random_07.txt AC 59 ms 76548 KiB
random_08.txt AC 65 ms 76780 KiB
random_09.txt AC 60 ms 76556 KiB
random_10.txt AC 68 ms 81340 KiB
random_11.txt AC 59 ms 76436 KiB
random_12.txt AC 66 ms 76700 KiB
random_13.txt AC 66 ms 81080 KiB
random_14.txt AC 68 ms 80884 KiB
random_15.txt AC 64 ms 80800 KiB
random_16.txt AC 60 ms 76536 KiB
random_17.txt AC 70 ms 81504 KiB
random_18.txt AC 71 ms 81432 KiB
random_19.txt AC 71 ms 81156 KiB
random_20.txt AC 69 ms 81124 KiB
random_21.txt AC 71 ms 81024 KiB
random_22.txt AC 71 ms 81116 KiB
sample_01.txt AC 59 ms 76488 KiB
sample_02.txt AC 58 ms 76480 KiB
sample_03.txt AC 59 ms 76568 KiB


2025-06-16 (Mon)
14:17:52 +09:00