Submission #66768771
Source Code Expand
Copy
import sys, time, random, heapq, math, itertoolsfrom collections import deque, Counter, defaultdictfrom sortedcontainers import SortedSet, SortedListfrom bisect import bisect, bisect_left, bisect_rightimport heapq as hqfrom functools import cache, cmp_to_keydef debug(*x):print('debug:',*x, file=sys.stderr)sys.setrecursionlimit(300000)input = lambda: sys.stdin.readline().rstrip()ii = lambda: int(input())mi = lambda: map(int, input().split())li = lambda: list(mi())inf = 2 ** 61 - 1mod = 998244353def dfs(n,cnt):global base,dd[n] = cntfor k,w in g[n]:if d[k] != -1:temp = cnt ^ w ^ d[k]
import sys, time, random, heapq, math, itertools
from collections import deque, Counter, defaultdict
from sortedcontainers import SortedSet, SortedList
from bisect import bisect, bisect_left, bisect_right
import heapq as hq
from functools import cache, cmp_to_key
def debug(*x):print('debug:',*x, file=sys.stderr)
sys.setrecursionlimit(300000)
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1
mod = 998244353
def dfs(n,cnt):
global base,d
d[n] = cnt
for k,w in g[n]:
if d[k] != -1:
temp = cnt ^ w ^ d[k]
if temp > 0:
for b in base:
temp = min(temp, temp^b)
if temp > 0:
base.append(temp)
base.sort(reverse=True)
else:
dfs(k, cnt^w)
N,M = mi()
g = [[] for _ in range(N)]
for i in range(M):
a,b,w = mi()
a-=1; b-=1
g[a].append([b,w])
d = [-1]*N
base = []
dfs(0,0)
#print(d)
#print(base)
if d[N-1] == -1:
print(-1)
exit()
ans = d[N-1]
for b in base:
ans = min(ans, ans ^ b)
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | poisonkumaa |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 1241 Byte |
| Status | WA |
| Exec Time | 160 ms |
| Memory | 88688 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 | 152 ms | 88024 KiB |
| hand_02.txt | AC | 158 ms | 87628 KiB |
| hand_03.txt | AC | 157 ms | 87636 KiB |
| hand_04.txt | AC | 157 ms | 88024 KiB |
| hand_05.txt | AC | 158 ms | 87784 KiB |
| hand_06.txt | WA | 155 ms | 87608 KiB |
| hand_07.txt | WA | 156 ms | 87932 KiB |
| hand_08.txt | WA | 155 ms | 87900 KiB |
| random_01.txt | AC | 148 ms | 87956 KiB |
| random_02.txt | AC | 155 ms | 88344 KiB |
| random_03.txt | AC | 154 ms | 87644 KiB |
| random_04.txt | AC | 158 ms | 88136 KiB |
| random_05.txt | AC | 158 ms | 87812 KiB |
| random_06.txt | AC | 159 ms | 88152 KiB |
| random_07.txt | AC | 157 ms | 87900 KiB |
| random_08.txt | AC | 160 ms | 88128 KiB |
| random_09.txt | AC | 155 ms | 87824 KiB |
| random_10.txt | AC | 151 ms | 88456 KiB |
| random_11.txt | AC | 145 ms | 87632 KiB |
| random_12.txt | AC | 150 ms | 88300 KiB |
| random_13.txt | AC | 150 ms | 88164 KiB |
| random_14.txt | AC | 155 ms | 88120 KiB |
| random_15.txt | AC | 156 ms | 88144 KiB |
| random_16.txt | AC | 154 ms | 87808 KiB |
| random_17.txt | AC | 158 ms | 88548 KiB |
| random_18.txt | AC | 157 ms | 88688 KiB |
| random_19.txt | AC | 156 ms | 88448 KiB |
| random_20.txt | AC | 157 ms | 88348 KiB |
| random_21.txt | AC | 160 ms | 87704 KiB |
| random_22.txt | AC | 153 ms | 87988 KiB |
| sample_01.txt | AC | 153 ms | 87816 KiB |
| sample_02.txt | AC | 154 ms | 87812 KiB |
| sample_03.txt | AC | 155 ms | 87960 KiB |