Submission #66774382
Source Code Expand
Copy
import sysfrom collections import dequedef main():input = sys.stdin.read().split()ptr = 0N = int(input[ptr])ptr += 1M = int(input[ptr])ptr += 1adj = [[] for _ in range(N+1)]for _ in range(M):a = int(input[ptr])ptr += 1b = int(input[ptr])ptr += 1w = int(input[ptr])ptr += 1adj[a].append((b, w))
import sys from collections import deque def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 adj = [[] for _ in range(N+1)] for _ in range(M): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 w = int(input[ptr]) ptr += 1 adj[a].append((b, w)) INF = 1 << 60 dist = [INF] * (N + 1) dist[1] = 0 q = deque([1]) while q: u = q.popleft() for (v, w) in adj[u]: if dist[v] == INF: dist[v] = dist[u] ^ w q.append(v) if dist[N] == INF: print(-1) return basis = [] def add_to_basis(x): for b in basis: x = min(x, x ^ b) if x != 0: basis.append(x) basis.sort(reverse=True) for u in range(1, N+1): if dist[u] == INF: continue for (v, w) in adj[u]: if dist[v] != INF: cycle_xor = dist[u] ^ w ^ dist[v] add_to_basis(cycle_xor) res = dist[N] for b in basis: res = min(res, res ^ b) print(res) if __name__ == '__main__': main()
Submission Info
Submission Time | |
---|---|
Task | D - XOR Shortest Walk |
User | aiko_cse4 |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 0 |
Code Size | 1316 Byte |
Status | WA |
Exec Time | 88 ms |
Memory | 81080 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 | 80 ms | 77024 KiB |
hand_02.txt | AC | 80 ms | 76784 KiB |
hand_03.txt | AC | 80 ms | 76764 KiB |
hand_04.txt | AC | 79 ms | 76800 KiB |
hand_05.txt | AC | 79 ms | 76716 KiB |
hand_06.txt | WA | 79 ms | 76768 KiB |
hand_07.txt | WA | 77 ms | 76920 KiB |
hand_08.txt | WA | 79 ms | 76744 KiB |
random_01.txt | AC | 79 ms | 76664 KiB |
random_02.txt | AC | 81 ms | 76568 KiB |
random_03.txt | AC | 80 ms | 76748 KiB |
random_04.txt | AC | 83 ms | 76588 KiB |
random_05.txt | AC | 81 ms | 76748 KiB |
random_06.txt | AC | 80 ms | 76936 KiB |
random_07.txt | AC | 81 ms | 76700 KiB |
random_08.txt | AC | 82 ms | 76760 KiB |
random_09.txt | AC | 81 ms | 76932 KiB |
random_10.txt | AC | 83 ms | 76956 KiB |
random_11.txt | AC | 82 ms | 76784 KiB |
random_12.txt | AC | 83 ms | 76764 KiB |
random_13.txt | AC | 87 ms | 80952 KiB |
random_14.txt | AC | 87 ms | 81080 KiB |
random_15.txt | AC | 85 ms | 80892 KiB |
random_16.txt | AC | 83 ms | 77116 KiB |
random_17.txt | AC | 85 ms | 76928 KiB |
random_18.txt | AC | 83 ms | 76812 KiB |
random_19.txt | AC | 82 ms | 76652 KiB |
random_20.txt | AC | 84 ms | 76664 KiB |
random_21.txt | AC | 88 ms | 80880 KiB |
random_22.txt | AC | 86 ms | 81052 KiB |
sample_01.txt | AC | 82 ms | 76740 KiB |
sample_02.txt | AC | 82 ms | 76812 KiB |
sample_03.txt | AC | 80 ms | 76540 KiB |