Submission #66739568
Source Code Expand
Copy
from collections import dequeN,M=map(int,input().split())G=[[] for _ in range(N)]for _ in range(M):a,b,w=map(int,input().split())a-=1b-=1G[a].append((b,w))G[b].append((a,w))dist=[-1]*Ndist[0]=0q=deque()q.append(0)while q:v=q.popleft()for nv,w in G[v]:if dist[nv]==-1:dist[nv]=dist[v]^wq.append(nv)basis=[]
from collections import deque
N,M=map(int,input().split())
G=[[] for _ in range(N)]
for _ in range(M):
a,b,w=map(int,input().split())
a-=1
b-=1
G[a].append((b,w))
G[b].append((a,w))
dist=[-1]*N
dist[0]=0
q=deque()
q.append(0)
while q:
v=q.popleft()
for nv,w in G[v]:
if dist[nv]==-1:
dist[nv]=dist[v]^w
q.append(nv)
basis=[]
visited=[False]*N
def dfs(v):
visited[v]=True
for nv,w in G[v]:
if dist[nv] != -1:
cycle=dist[v]^w^dist[nv]
if cycle != 0:
for b in basis:
cycle=min(cycle,cycle^b)
if cycle != 0:
basis.append(cycle)
else:
dist[nv]=dist[v]^w
dfs(nv)
dist=[-1]*N
dist[0]=0
dfs(0)
ans=dist[N - 1]
if ans==-1:
print(-1)
else:
for b in basis:
ans=min(ans,ans^b)
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | Untitle |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 946 Byte |
| Status | WA |
| Exec Time | 92 ms |
| Memory | 84252 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 | 71 ms | 77092 KiB |
| hand_02.txt | AC | 72 ms | 76920 KiB |
| hand_03.txt | WA | 71 ms | 76888 KiB |
| hand_04.txt | AC | 72 ms | 76952 KiB |
| hand_05.txt | WA | 72 ms | 76880 KiB |
| hand_06.txt | WA | 72 ms | 76592 KiB |
| hand_07.txt | WA | 72 ms | 76780 KiB |
| hand_08.txt | WA | 72 ms | 76788 KiB |
| random_01.txt | AC | 72 ms | 76956 KiB |
| random_02.txt | AC | 81 ms | 81652 KiB |
| random_03.txt | AC | 71 ms | 76860 KiB |
| random_04.txt | AC | 76 ms | 77016 KiB |
| random_05.txt | AC | 72 ms | 76876 KiB |
| random_06.txt | AC | 74 ms | 77004 KiB |
| random_07.txt | AC | 79 ms | 76816 KiB |
| random_08.txt | AC | 80 ms | 81836 KiB |
| random_09.txt | AC | 71 ms | 76968 KiB |
| random_10.txt | AC | 85 ms | 82188 KiB |
| random_11.txt | AC | 73 ms | 76944 KiB |
| random_12.txt | AC | 81 ms | 81436 KiB |
| random_13.txt | AC | 80 ms | 81048 KiB |
| random_14.txt | AC | 83 ms | 81672 KiB |
| random_15.txt | AC | 79 ms | 80924 KiB |
| random_16.txt | AC | 74 ms | 76768 KiB |
| random_17.txt | AC | 91 ms | 83844 KiB |
| random_18.txt | AC | 92 ms | 83932 KiB |
| random_19.txt | AC | 92 ms | 84252 KiB |
| random_20.txt | AC | 92 ms | 83264 KiB |
| random_21.txt | AC | 86 ms | 81884 KiB |
| random_22.txt | AC | 91 ms | 83200 KiB |
| sample_01.txt | AC | 72 ms | 76916 KiB |
| sample_02.txt | AC | 73 ms | 76732 KiB |
| sample_03.txt | AC | 72 ms | 76872 KiB |