Submission #66765339
Source Code Expand
Copy
#合わないなと思ったらケース違った#Why?#有向グラフですかそうですか……#まだあるんですか……#サイクルを成すかの条件がビミョいので逆向きグラフを作るN,M = map(int,input().split())graph = [[] for _ in range(N)]rgraph = [[] for _ in range(N)]for i in range(M):a,b,w = map(int,input().split())a -= 1; b -= 1graph[a].append((b,w))rgraph[b].append(a)dist = [None]*Ndist[0] = 0can_go_N = [False]*N
#合わないなと思ったらケース違った
#Why?
#有向グラフですかそうですか……
#まだあるんですか……
#サイクルを成すかの条件がビミョいので逆向きグラフを作る
N,M = map(int,input().split())
graph = [[] for _ in range(N)]
rgraph = [[] for _ in range(N)]
for i in range(M):
a,b,w = map(int,input().split())
a -= 1; b -= 1
graph[a].append((b,w))
rgraph[b].append(a)
dist = [None]*N
dist[0] = 0
can_go_N = [False]*N
from collections import deque
queue = deque()
can_go_N[-1] = True
queue.append(N-1)
while queue:
u = queue.popleft()
for v in rgraph[u]:
if not can_go_N[v]:
can_go_N[v] = True
queue.append(v)
values = []
def dfs(u):
stack = [u]
while stack:
u = stack.pop()
for v,w in graph[u]:
if not can_go_N[v]:
continue
if dist[v] == None:
dist[v] = dist[u]^w
stack.append(v)
else:
x = dist[u]^dist[v]^w
if x:
values.append(x)
if can_go_N[0] == False:
exit(print(-1))
else:
dfs(0)
if dist[N-1] == None:
exit(print(-1))
bit = [0]*60
for x in values:
v = x
for b in range(60-1,-1,-1):
if not (v>>b)&1:
continue
if bit[b] == 0:
bit[b] = v
break
v ^= bit[b]
ans = dist[N-1]
for b in range(60-1,-1,-1):
if bit[b] and (ans^bit[b]) < ans:
ans ^=bit[b]
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | katsuta |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 1616 Byte |
| Status | WA |
| Exec Time | 84 ms |
| Memory | 81856 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 | 76984 KiB |
| hand_02.txt | AC | 71 ms | 76832 KiB |
| hand_03.txt | AC | 72 ms | 76812 KiB |
| hand_04.txt | AC | 71 ms | 77100 KiB |
| hand_05.txt | AC | 72 ms | 76836 KiB |
| hand_06.txt | AC | 73 ms | 76696 KiB |
| hand_07.txt | WA | 72 ms | 77016 KiB |
| hand_08.txt | WA | 72 ms | 76756 KiB |
| random_01.txt | AC | 72 ms | 76696 KiB |
| random_02.txt | AC | 79 ms | 76880 KiB |
| random_03.txt | AC | 72 ms | 76856 KiB |
| random_04.txt | AC | 76 ms | 76876 KiB |
| random_05.txt | AC | 72 ms | 76608 KiB |
| random_06.txt | AC | 74 ms | 76848 KiB |
| random_07.txt | AC | 71 ms | 76860 KiB |
| random_08.txt | AC | 77 ms | 76856 KiB |
| random_09.txt | AC | 72 ms | 76824 KiB |
| random_10.txt | AC | 82 ms | 81004 KiB |
| random_11.txt | AC | 72 ms | 76984 KiB |
| random_12.txt | AC | 79 ms | 76712 KiB |
| random_13.txt | AC | 79 ms | 81856 KiB |
| random_14.txt | AC | 80 ms | 81712 KiB |
| random_15.txt | AC | 77 ms | 81372 KiB |
| random_16.txt | AC | 72 ms | 76840 KiB |
| random_17.txt | AC | 84 ms | 80988 KiB |
| random_18.txt | AC | 84 ms | 80820 KiB |
| random_19.txt | AC | 82 ms | 80916 KiB |
| random_20.txt | AC | 82 ms | 80804 KiB |
| random_21.txt | AC | 82 ms | 80988 KiB |
| random_22.txt | AC | 83 ms | 80880 KiB |
| sample_01.txt | AC | 71 ms | 76828 KiB |
| sample_02.txt | AC | 71 ms | 76768 KiB |
| sample_03.txt | AC | 71 ms | 76696 KiB |