Submission #66752638
Source Code Expand
Copy
import sysdef input():return sys.stdin.readline().rstrip()def main():import networkx as nxn, m = map(int, input().split())g = nx.DiGraph()g.add_nodes_from(range(1, n+1))for _ in range(m):a, b, w = map(int, input().split())g.add_edge(a, b, weight=w)dist = {i: None for i in range(1, n+1)}dist[1] = 0stack = [1]cycle = []while stack:
import sys
def input():return sys.stdin.readline().rstrip()
def main():
import networkx as nx
n, m = map(int, input().split())
g = nx.DiGraph()
g.add_nodes_from(range(1, n+1))
for _ in range(m):
a, b, w = map(int, input().split())
g.add_edge(a, b, weight=w)
dist = {i: None for i in range(1, n+1)}
dist[1] = 0
stack = [1]
cycle = []
while stack:
u = stack.pop()
for v in g[u]:
w = g[u][v]['weight']
x = dist[u] ^ w
if dist[v] is None:
dist[v] = x
stack.append(v)
else:
cycle.append(x^dist[v])
if dist[n] is None:
print(-1); return
bit = []
for x in cycle:
for b in bit:
x = min(x, x^b)
if x:
bit.append(x)
ans = dist[n]
for b in bit:
ans = min(ans, ans^b)
print(ans)
if __name__ == '__main__':
sys.exit(main())
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | Xx_RYO_xX |
| Language | Python (CPython 3.11.4) |
| Score | 0 |
| Code Size | 1057 Byte |
| Status | WA |
| Exec Time | 114 ms |
| Memory | 29920 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 | 110 ms | 28804 KiB |
| hand_02.txt | AC | 110 ms | 28732 KiB |
| hand_03.txt | AC | 111 ms | 28640 KiB |
| hand_04.txt | AC | 111 ms | 28728 KiB |
| hand_05.txt | AC | 110 ms | 28692 KiB |
| hand_06.txt | WA | 111 ms | 28692 KiB |
| hand_07.txt | WA | 111 ms | 28720 KiB |
| hand_08.txt | AC | 111 ms | 28976 KiB |
| random_01.txt | AC | 111 ms | 28700 KiB |
| random_02.txt | AC | 112 ms | 29520 KiB |
| random_03.txt | AC | 112 ms | 28912 KiB |
| random_04.txt | AC | 111 ms | 29188 KiB |
| random_05.txt | AC | 110 ms | 28804 KiB |
| random_06.txt | AC | 112 ms | 28796 KiB |
| random_07.txt | AC | 110 ms | 28636 KiB |
| random_08.txt | AC | 113 ms | 29380 KiB |
| random_09.txt | AC | 111 ms | 28844 KiB |
| random_10.txt | AC | 113 ms | 29652 KiB |
| random_11.txt | AC | 109 ms | 28812 KiB |
| random_12.txt | AC | 112 ms | 29272 KiB |
| random_13.txt | AC | 111 ms | 28780 KiB |
| random_14.txt | AC | 112 ms | 28976 KiB |
| random_15.txt | AC | 111 ms | 28668 KiB |
| random_16.txt | AC | 112 ms | 29148 KiB |
| random_17.txt | AC | 114 ms | 29920 KiB |
| random_18.txt | AC | 114 ms | 29760 KiB |
| random_19.txt | AC | 113 ms | 29656 KiB |
| random_20.txt | AC | 114 ms | 29220 KiB |
| random_21.txt | AC | 113 ms | 29536 KiB |
| random_22.txt | AC | 114 ms | 29456 KiB |
| sample_01.txt | AC | 111 ms | 28676 KiB |
| sample_02.txt | AC | 110 ms | 29008 KiB |
| sample_03.txt | AC | 111 ms | 28928 KiB |