Submission #66767040
Source Code Expand
Copy
from collections import dequeimport syssys.setrecursionlimit(10**7)N, M = map(int, input().split())graph = {i: [] for i in range(N)}for _ in range(M):u, v, w = map(int, input().split())graph[u-1].append((v-1, w))d = [0] * Nvisited = [False] * Ncycles = []def dfs(u):visited[u] = Truefor v, w in graph[u]:x = d[u] ^ wif not visited[v]:d[v] = xdfs(v)else:
from collections import deque import sys sys.setrecursionlimit(10**7) N, M = map(int, input().split()) graph = {i: [] for i in range(N)} for _ in range(M): u, v, w = map(int, input().split()) graph[u-1].append((v-1, w)) d = [0] * N visited = [False] * N cycles = [] def dfs(u): visited[u] = True for v, w in graph[u]: x = d[u] ^ w if not visited[v]: d[v] = x dfs(v) else: cyc = x ^ d[v] if cyc: cycles.append(cyc) dfs(0) if not visited[N-1]: print(-1) exit() def build_basis(xs): B = [] for x in sorted(xs, reverse=True): for b in B: x = min(x, x ^ b) if x: B.append(x) return B basis = build_basis(cycles) res = d[N-1] for b in basis: res = min(res, res ^ b) print(res)
Submission Info
Submission Time | |
---|---|
Task | D - XOR Shortest Walk |
User | kangping |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 0 |
Code Size | 890 Byte |
Status | WA |
Exec Time | 90 ms |
Memory | 81804 KiB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||
Status |
|
|
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 | 76 ms | 76820 KiB |
hand_02.txt | AC | 76 ms | 76996 KiB |
hand_03.txt | AC | 77 ms | 76848 KiB |
hand_04.txt | AC | 79 ms | 76636 KiB |
hand_05.txt | AC | 79 ms | 76856 KiB |
hand_06.txt | WA | 79 ms | 77044 KiB |
hand_07.txt | WA | 79 ms | 76792 KiB |
hand_08.txt | WA | 79 ms | 77056 KiB |
random_01.txt | AC | 80 ms | 76764 KiB |
random_02.txt | AC | 84 ms | 77188 KiB |
random_03.txt | AC | 78 ms | 77004 KiB |
random_04.txt | AC | 83 ms | 76912 KiB |
random_05.txt | AC | 79 ms | 77084 KiB |
random_06.txt | AC | 80 ms | 77032 KiB |
random_07.txt | AC | 78 ms | 76792 KiB |
random_08.txt | AC | 82 ms | 77120 KiB |
random_09.txt | AC | 77 ms | 76816 KiB |
random_10.txt | AC | 86 ms | 81784 KiB |
random_11.txt | AC | 79 ms | 76936 KiB |
random_12.txt | AC | 85 ms | 77224 KiB |
random_13.txt | AC | 87 ms | 81172 KiB |
random_14.txt | AC | 86 ms | 80876 KiB |
random_15.txt | AC | 82 ms | 81288 KiB |
random_16.txt | AC | 79 ms | 76680 KiB |
random_17.txt | AC | 90 ms | 81804 KiB |
random_18.txt | AC | 90 ms | 81268 KiB |
random_19.txt | AC | 89 ms | 81264 KiB |
random_20.txt | AC | 85 ms | 81476 KiB |
random_21.txt | AC | 88 ms | 80868 KiB |
random_22.txt | AC | 90 ms | 81212 KiB |
sample_01.txt | AC | 79 ms | 76816 KiB |
sample_02.txt | AC | 80 ms | 76800 KiB |
sample_03.txt | AC | 80 ms | 76948 KiB |