Submission #66748218


Source Code Expand

Copy
# Original C++ Code:
#
# #include <bits/stdc++.h>
#
# using namespace std;
#
# const int N = 1e5 + 1;
#
# struct Basis{
# vector<int>basis;
# Basis(){
# }
# void insert(int x){
# for (int i : basis) {
# x = min(x, x ^ i);
# }
# if (x) basis.push_back(x);
# }
# int get(int x) {
# for (int i : basis) {
# x = min(x, x ^ i);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Original C++ Code:
# 
# #include <bits/stdc++.h>
# 
# using namespace std;
# 
# const int N = 1e5 + 1;
# 
# struct Basis{
#     vector<int>basis;
#     Basis(){
#     }
#     void insert(int x){
#         for (int i : basis) {
#             x = min(x, x ^ i);
#         }
#         if (x) basis.push_back(x);
#     }
#     int get(int x) {
#         for (int i : basis) {
#             x = min(x, x ^ i);
#         }
#         return x;
#     }
# };
# 
# vector<pair<int, int>> g[N];
# bool vis[N];
# int XOR[N];
# Basis b;
# 
# void dfs(int u, int p = -1, int d = 0) {
#     vis[u] = true;
#     XOR[u] = d;
#     for (auto [v, w]: g[u]) {
#         if (!vis[v]) {
#             dfs(v, u, w ^ d);
#         }
#         else if (v != p) {
#             b.insert(XOR[u] ^ XOR[v] ^ w);
#         }
#     }
# }
# 
# void do_work(){
#     int n, m;
#     cin >> n >> m;
#     for (int i = 0; i < m; i++) {
#         int u, v, w;
#         cin >> u >> v >> w;
#         u--; v--;
#         g[u].emplace_back(v, w);
#         g[v].emplace_back(u, w);
#     }
#     dfs(0);
#     cout << b.get(XOR[n - 1]) << '\n';
# }
# 
# int main(){
# #ifndef ONLINE_JUDGE
#     freopen("input.txt", "r", stdin);
#     freopen("output.txt", "w", stdout);
# #endif
#     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#     int T = 1;
#     for(int i = 1; i <= T; i++){
#         do_work();
#     }
# }

# Translated Python Code:

import sys
sys.setrecursionlimit(10**6)

N = 10**5 + 1

class Basis:
    def __init__(self):
        self.basis = []

    def insert(self, x):
        for i in self.basis:
            x = min(x, x ^ i)
        if x:
            self.basis.append(x)

    def get(self, x):
        for i in self.basis:
            x = min(x, x ^ i)
        return x

g = [[] for _ in range(N)]
vis = [False] * N
XOR = [0] * N
b = Basis()

def dfs(u, p=-1, d=0):
    vis[u] = True
    XOR[u] = d
    for vw in g[u]:
        v, w = vw
        if not vis[v]:
            dfs(v, u, w ^ d)
        elif v != p:
            b.insert(XOR[u] ^ XOR[v] ^ w)

def do_work():
    n, m = map(int, sys.stdin.readline().split())
    for _ in range(m):
        u, v, w = map(int, sys.stdin.readline().split())
        u -= 1
        v -= 1
        g[u].append((v, w))
    dfs(0)
    ans = b.get(XOR[n - 1])
    if not vis[n-1]:
      print(-1)
    else:
      print(ans)

if __name__ == "__main__":
    T = 1
    for _ in range(T):
        do_work()

Submission Info

Submission Time
Task D - XOR Shortest Walk
User Arou
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 2576 Byte
Status WA
Exec Time 64 ms
Memory 83360 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 28
WA × 5
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 61 ms 82756 KiB
hand_02.txt AC 61 ms 82780 KiB
hand_03.txt AC 61 ms 82628 KiB
hand_04.txt AC 61 ms 82692 KiB
hand_05.txt AC 60 ms 82784 KiB
hand_06.txt WA 60 ms 82812 KiB
hand_07.txt WA 61 ms 82536 KiB
hand_08.txt WA 62 ms 82576 KiB
random_01.txt AC 62 ms 82640 KiB
random_02.txt AC 62 ms 83152 KiB
random_03.txt AC 61 ms 82736 KiB
random_04.txt AC 62 ms 83276 KiB
random_05.txt AC 62 ms 82724 KiB
random_06.txt AC 62 ms 82644 KiB
random_07.txt AC 62 ms 82632 KiB
random_08.txt AC 63 ms 83124 KiB
random_09.txt AC 61 ms 82836 KiB
random_10.txt AC 63 ms 83168 KiB
random_11.txt AC 61 ms 82760 KiB
random_12.txt AC 63 ms 83176 KiB
random_13.txt AC 64 ms 83300 KiB
random_14.txt AC 64 ms 83120 KiB
random_15.txt AC 63 ms 83068 KiB
random_16.txt AC 62 ms 82756 KiB
random_17.txt AC 64 ms 83360 KiB
random_18.txt AC 64 ms 83160 KiB
random_19.txt AC 64 ms 83340 KiB
random_20.txt AC 64 ms 82880 KiB
random_21.txt WA 63 ms 82676 KiB
random_22.txt WA 63 ms 82552 KiB
sample_01.txt AC 61 ms 82824 KiB
sample_02.txt AC 61 ms 82780 KiB
sample_03.txt AC 62 ms 82808 KiB


2025-06-16 (Mon)
14:46:43 +09:00