Submission #66738862
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())G[a-1].append((b-1,w))dist=[-1]*Ndist[0]=0que=deque()que.append(0)base=[]while que:u=que.popleft()for v,c in G[u]:x=dist[u]^cif dist[v]==-1:dist[v]=xque.append(v)else:cycle=dist[v]^xif cycle!=0:
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())
G[a-1].append((b-1,w))
dist=[-1]*N
dist[0]=0
que=deque()
que.append(0)
base=[]
while que:
u=que.popleft()
for v,c in G[u]:
x=dist[u]^c
if dist[v]==-1:
dist[v]=x
que.append(v)
else:
cycle=dist[v]^x
if cycle!=0:
for b in base:
cycle=min(cycle,cycle^b)
if cycle!=0:
base.append(cycle)
if dist[N-1]==-1:
print(-1)
else:
ans=dist[N-1]
for b in base:
ans=min(ans,ans^b)
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | nicola0518 |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 725 Byte |
| Status | WA |
| Exec Time | 88 ms |
| Memory | 81788 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 | 73 ms | 76844 KiB |
| hand_02.txt | AC | 72 ms | 76952 KiB |
| hand_03.txt | AC | 75 ms | 76868 KiB |
| hand_04.txt | AC | 75 ms | 76832 KiB |
| hand_05.txt | AC | 76 ms | 76912 KiB |
| hand_06.txt | WA | 75 ms | 77064 KiB |
| hand_07.txt | WA | 76 ms | 76876 KiB |
| hand_08.txt | WA | 75 ms | 76812 KiB |
| random_01.txt | AC | 76 ms | 77008 KiB |
| random_02.txt | AC | 81 ms | 77076 KiB |
| random_03.txt | AC | 75 ms | 77188 KiB |
| random_04.txt | AC | 78 ms | 76960 KiB |
| random_05.txt | AC | 74 ms | 76744 KiB |
| random_06.txt | AC | 74 ms | 76988 KiB |
| random_07.txt | AC | 74 ms | 76812 KiB |
| random_08.txt | AC | 77 ms | 76780 KiB |
| random_09.txt | AC | 76 ms | 76940 KiB |
| random_10.txt | AC | 84 ms | 80888 KiB |
| random_11.txt | AC | 75 ms | 76696 KiB |
| random_12.txt | AC | 80 ms | 76912 KiB |
| random_13.txt | AC | 83 ms | 81216 KiB |
| random_14.txt | AC | 84 ms | 81184 KiB |
| random_15.txt | AC | 82 ms | 81384 KiB |
| random_16.txt | AC | 75 ms | 76744 KiB |
| random_17.txt | AC | 87 ms | 80896 KiB |
| random_18.txt | AC | 84 ms | 81200 KiB |
| random_19.txt | AC | 83 ms | 81216 KiB |
| random_20.txt | AC | 87 ms | 81788 KiB |
| random_21.txt | AC | 85 ms | 81248 KiB |
| random_22.txt | AC | 88 ms | 80964 KiB |
| sample_01.txt | AC | 76 ms | 76860 KiB |
| sample_02.txt | AC | 74 ms | 77036 KiB |
| sample_03.txt | AC | 73 ms | 76864 KiB |