Submission #66757494


Source Code Expand

Copy
#!/usr/bin/env python3
from collections import deque
# Generated by 2.14.0 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
A, B, W = map(int, input().split())
G[A-1].append((B-1, W))
dist = [-1] * N
dist[0] = 0
xor_basis = []
que = deque([0])
while que:
v = que.popleft()
for u, w in G[v]:
if dist[u] == -1:
dist[u] = dist[v] ^ w
que.append(u)
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#!/usr/bin/env python3
from collections import deque

# Generated by 2.14.0 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        A, B, W = map(int, input().split())
        G[A-1].append((B-1, W))
    dist = [-1] * N
    dist[0] = 0
    xor_basis = []

    que = deque([0])
    while que:
        v = que.popleft()
        for u, w in G[v]:
            if dist[u] == -1:
                dist[u] = dist[v] ^ w
                que.append(u)
            else:
                cycle_xor = dist[u] ^ dist[v] ^ w
                xor_basis.append(cycle_xor)

    if dist[N - 1] == -1:
        print(-1)
        return

    xor_basis_sorted = []

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

    for x in xor_basis:
        insert_basis(x)


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

    print(res)

if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task D - XOR Shortest Walk
User atososon
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1274 Byte
Status WA
Exec Time 79 ms
Memory 81340 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 70 ms 76936 KiB
hand_02.txt AC 67 ms 76988 KiB
hand_03.txt AC 66 ms 76704 KiB
hand_04.txt AC 66 ms 77156 KiB
hand_05.txt AC 66 ms 76808 KiB
hand_06.txt WA 67 ms 76904 KiB
hand_07.txt WA 67 ms 76800 KiB
hand_08.txt WA 67 ms 76824 KiB
random_01.txt AC 67 ms 76688 KiB
random_02.txt AC 73 ms 76812 KiB
random_03.txt AC 68 ms 76884 KiB
random_04.txt AC 72 ms 77156 KiB
random_05.txt AC 68 ms 76960 KiB
random_06.txt AC 70 ms 76840 KiB
random_07.txt AC 68 ms 76780 KiB
random_08.txt AC 73 ms 76716 KiB
random_09.txt AC 69 ms 77020 KiB
random_10.txt AC 75 ms 81164 KiB
random_11.txt AC 69 ms 76940 KiB
random_12.txt AC 74 ms 76796 KiB
random_13.txt AC 73 ms 80848 KiB
random_14.txt AC 74 ms 81340 KiB
random_15.txt AC 72 ms 81184 KiB
random_16.txt AC 68 ms 76788 KiB
random_17.txt AC 78 ms 80924 KiB
random_18.txt AC 78 ms 80812 KiB
random_19.txt AC 78 ms 80808 KiB
random_20.txt AC 78 ms 81088 KiB
random_21.txt AC 79 ms 80960 KiB
random_22.txt AC 79 ms 81264 KiB
sample_01.txt AC 68 ms 76752 KiB
sample_02.txt AC 68 ms 76964 KiB
sample_03.txt AC 68 ms 77076 KiB


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