Submission #66759619


Source Code Expand

Copy
import sys, math, bisect, itertools, pprint, collections
from collections import deque, defaultdict
from heapq import heappush, heappop, heapify
from sortedcontainers import SortedSet, SortedList, SortedDict
###
input = sys.stdin.readline
INF = 10 ** 20
sys.setrecursionlimit(10 ** 8)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
N, M = map(int, input().split())
tmp = [list(map(int, input().split())) for _ in range(M)]
A = [t[0] for t in tmp]
B = [t[1] for t in tmp]
W = [t[2] for t in tmp]
graph = [[] for _ in range(N)]
for i in range(M):
graph[A[i] - 1].append((B[i] - 1, W[i]))
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys, math, bisect, itertools, pprint, collections
from collections import deque, defaultdict
from heapq import heappush, heappop, heapify
from sortedcontainers import SortedSet, SortedList, SortedDict

###おまじない
input = sys.stdin.readline
INF = 10 ** 20
sys.setrecursionlimit(10 ** 8)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

N, M = map(int, input().split())
tmp = [list(map(int, input().split())) for _ in range(M)]
A = [t[0] for t in tmp]
B = [t[1] for t in tmp]
W = [t[2] for t in tmp]

graph = [[] for _ in range(N)]
for i in range(M):
    graph[A[i] - 1].append((B[i] - 1, W[i]))

dist = [-1] * N
basis = []

def dfs(u):
    for v, w in graph[u]:
        path_xor_to_v = dist[u] ^ w
        if dist[v] == -1:
            dist[v] = path_xor_to_v
            dfs(v)
        else:
            cycle_xor = path_xor_to_v ^ dist[v]
            if cycle_xor > 0:
                for i in basis:
                    cycle_xor = min(cycle_xor, cycle_xor ^ i)
                if cycle_xor > 0:
                    basis.append(cycle_xor)

dist[0] = 0
dfs(0)

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















Submission Info

Submission Time
Task D - XOR Shortest Walk
User takahashi_shota
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1306 Byte
Status WA
Exec Time 272 ms
Memory 95156 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 248 ms 93892 KiB
hand_02.txt AC 251 ms 93896 KiB
hand_03.txt AC 255 ms 94016 KiB
hand_04.txt AC 253 ms 93716 KiB
hand_05.txt AC 255 ms 94072 KiB
hand_06.txt WA 247 ms 93748 KiB
hand_07.txt WA 247 ms 93772 KiB
hand_08.txt WA 260 ms 94048 KiB
random_01.txt AC 254 ms 93740 KiB
random_02.txt AC 266 ms 94856 KiB
random_03.txt AC 258 ms 94240 KiB
random_04.txt AC 251 ms 94420 KiB
random_05.txt AC 249 ms 93744 KiB
random_06.txt AC 262 ms 94344 KiB
random_07.txt AC 254 ms 94120 KiB
random_08.txt AC 257 ms 94560 KiB
random_09.txt AC 246 ms 94100 KiB
random_10.txt AC 256 ms 94912 KiB
random_11.txt AC 251 ms 94044 KiB
random_12.txt AC 263 ms 94628 KiB
random_13.txt AC 270 ms 94300 KiB
random_14.txt AC 268 ms 94560 KiB
random_15.txt AC 258 ms 94068 KiB
random_16.txt AC 253 ms 93880 KiB
random_17.txt AC 260 ms 95032 KiB
random_18.txt AC 269 ms 94860 KiB
random_19.txt AC 271 ms 95156 KiB
random_20.txt AC 272 ms 94448 KiB
random_21.txt AC 259 ms 94328 KiB
random_22.txt AC 261 ms 94512 KiB
sample_01.txt AC 254 ms 93712 KiB
sample_02.txt AC 263 ms 94068 KiB
sample_03.txt AC 261 ms 93876 KiB


2025-06-16 (Mon)
13:55:38 +09:00