Submission #66780568
Source Code Expand
Copy
n,m-map(int, input().split())edges=[]for i in range(m):a,b,w=map(int, input().split())def solve(n, edges):from collections import defaultdict, dequegraph = defaultdict(list)for u, v, w in edges:graph[u].append((v, w))graph[v].append((u, w))dist = [-1] * (n + 1)dist[1] = 0basis = []def insert_basis(x):for b in basis:x = min(x, x ^ b)if x:basis.append(x)
n,m-map(int, input().split())
edges=[]
for i in range(m):
a,b,w=map(int, input().split())
def solve(n, edges):
from collections import defaultdict, deque
graph = defaultdict(list)
for u, v, w in edges:
graph[u].append((v, w))
graph[v].append((u, w))
dist = [-1] * (n + 1)
dist[1] = 0
basis = []
def insert_basis(x):
for b in basis:
x = min(x, x ^ b)
if x:
basis.append(x)
basis.sort(reverse=True)
dq = deque([1])
while dq:
u = dq.popleft()
for v, w in graph[u]:
xor_val = dist[u] ^ w
if dist[v] == -1:
dist[v] = xor_val
dq.append(v)
else:
cycle = xor_val ^ dist[v]
insert_basis(cycle)
res = dist[n]
for b in basis:
res = min(res, res ^ b)
return res
print(solve(n, edges))
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | korokke3 |
| Language | Python (CPython 3.11.4) |
| Score | 0 |
| Code Size | 968 Byte |
| Status | RE |
| Exec Time | 10 ms |
| Memory | 8940 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 | RE | 10 ms | 8940 KiB |
| hand_02.txt | RE | 9 ms | 8856 KiB |
| hand_03.txt | RE | 9 ms | 8736 KiB |
| hand_04.txt | RE | 9 ms | 8832 KiB |
| hand_05.txt | RE | 9 ms | 8864 KiB |
| hand_06.txt | RE | 9 ms | 8856 KiB |
| hand_07.txt | RE | 9 ms | 8740 KiB |
| hand_08.txt | RE | 10 ms | 8932 KiB |
| random_01.txt | RE | 9 ms | 8876 KiB |
| random_02.txt | RE | 10 ms | 8892 KiB |
| random_03.txt | RE | 10 ms | 8792 KiB |
| random_04.txt | RE | 9 ms | 8868 KiB |
| random_05.txt | RE | 9 ms | 8788 KiB |
| random_06.txt | RE | 9 ms | 8840 KiB |
| random_07.txt | RE | 9 ms | 8832 KiB |
| random_08.txt | RE | 9 ms | 8864 KiB |
| random_09.txt | RE | 9 ms | 8824 KiB |
| random_10.txt | RE | 9 ms | 8828 KiB |
| random_11.txt | RE | 9 ms | 8804 KiB |
| random_12.txt | RE | 10 ms | 8776 KiB |
| random_13.txt | RE | 9 ms | 8892 KiB |
| random_14.txt | RE | 9 ms | 8800 KiB |
| random_15.txt | RE | 9 ms | 8832 KiB |
| random_16.txt | RE | 9 ms | 8900 KiB |
| random_17.txt | RE | 9 ms | 8864 KiB |
| random_18.txt | RE | 9 ms | 8780 KiB |
| random_19.txt | RE | 9 ms | 8896 KiB |
| random_20.txt | RE | 9 ms | 8824 KiB |
| random_21.txt | RE | 9 ms | 8796 KiB |
| random_22.txt | RE | 9 ms | 8888 KiB |
| sample_01.txt | RE | 9 ms | 8880 KiB |
| sample_02.txt | RE | 9 ms | 8856 KiB |
| sample_03.txt | RE | 9 ms | 8768 KiB |