Submission #66765129
Source Code Expand
Copy
import syssys.setrecursionlimit(2000)input = sys.stdin.readlineclass XORBasis:def __init__(self):self.basis = []self.size = 0def add(self,val):for b in self.basis:val = min(val,val^b)if val>0:self.basis.append(val)self.basis.sort(reverse= True)self.size += 1def minimize(self,val):for b in self.basis:val = min(val,val^b)return valdef main():
import sys
sys.setrecursionlimit(2000)
input = sys.stdin.readline
class XORBasis:
def __init__(self):
self.basis = []
self.size = 0
def add(self,val):
for b in self.basis:
val = min(val,val^b)
if val>0:
self.basis.append(val)
self.basis.sort(reverse= True)
self.size += 1
def minimize(self,val):
for b in self.basis:
val = min(val,val^b)
return val
def main():
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))
graph[b].append((a,w))
dist = [-1]*(n+1)
basis = XORBasis()
def dfs(u,current_xor):
dist[u] = current_xor
for v,w in graph[u]:
if dist[v] != -1:
cycle = current_xor ^ w ^ dist[v]
if cycle > 0:
basis.add(cycle)
else:
dfs(v,current_xor ^ w)
dfs(1,0)
if dist[n] == -1:
print(-1)
else:
path = dist[n]
min_sum = basis.minimize(path)
print(min_sum)
if __name__ == "__main__":
main()
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | KuroKiii |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 1288 Byte |
| Status | WA |
| Exec Time | 65 ms |
| Memory | 81580 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 | 59 ms | 76528 KiB |
| hand_02.txt | AC | 59 ms | 76780 KiB |
| hand_03.txt | WA | 59 ms | 76492 KiB |
| hand_04.txt | AC | 59 ms | 76448 KiB |
| hand_05.txt | WA | 59 ms | 76520 KiB |
| hand_06.txt | WA | 59 ms | 76704 KiB |
| hand_07.txt | WA | 59 ms | 76868 KiB |
| hand_08.txt | WA | 59 ms | 76556 KiB |
| random_01.txt | AC | 59 ms | 76748 KiB |
| random_02.txt | AC | 63 ms | 81100 KiB |
| random_03.txt | AC | 58 ms | 76444 KiB |
| random_04.txt | AC | 59 ms | 76780 KiB |
| random_05.txt | AC | 59 ms | 76640 KiB |
| random_06.txt | AC | 59 ms | 76672 KiB |
| random_07.txt | AC | 59 ms | 76416 KiB |
| random_08.txt | AC | 62 ms | 80788 KiB |
| random_09.txt | AC | 59 ms | 76564 KiB |
| random_10.txt | AC | 63 ms | 81260 KiB |
| random_11.txt | AC | 59 ms | 76784 KiB |
| random_12.txt | AC | 61 ms | 80616 KiB |
| random_13.txt | AC | 63 ms | 80940 KiB |
| random_14.txt | AC | 64 ms | 81064 KiB |
| random_15.txt | AC | 63 ms | 80668 KiB |
| random_16.txt | AC | 59 ms | 76628 KiB |
| random_17.txt | AC | 63 ms | 81096 KiB |
| random_18.txt | AC | 65 ms | 81580 KiB |
| random_19.txt | AC | 65 ms | 81244 KiB |
| random_20.txt | AC | 65 ms | 81132 KiB |
| random_21.txt | AC | 64 ms | 80648 KiB |
| random_22.txt | AC | 65 ms | 80988 KiB |
| sample_01.txt | AC | 59 ms | 76576 KiB |
| sample_02.txt | AC | 60 ms | 76640 KiB |
| sample_03.txt | AC | 59 ms | 76376 KiB |