1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| #include <bits/stdc++.h> #define nmf(i, s, e) for (int i = s; i <= e; i++) #define ref(i, s, e) for (int i = s; i >= e; i--) namespace FastIO { template <typename T> inline void read(T &x) { short neg = 1; char ch; while (ch = getchar(), !isdigit(ch)) if (ch == '-') neg = -1; x = ch - '0'; while (ch = getchar(), isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'); x *= neg; } template <typename T, typename... Args> inline void read(T &x, Args &...args) { read(x); read(args...); } template <typename T> inline void read(T *begin, T *end) { unsigned len = end - begin; for (unsigned i = 0; i < len; i++) read(*(begin + i)); } template <typename T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T, typename... Args> inline void write(T x, Args... args) { write(x); putchar(' '); write(args...); } template <typename T> inline void write(T *begin, T *end) { unsigned len = end - begin; for (unsigned i = 0; i < len; i++) write(*(begin + i)), putchar(' '); } } using namespace FastIO; using namespace std; typedef long long LL; typedef unsigned long long uLL;
class XORbasis { private: LL a[64];
public: XORbasis() { memset(a, 0, sizeof a); } void insert(LL x) { ref(i, 63, 0) { if (x >> i & 1) { if (!a[i]) { a[i] = x; break; } else x ^= a[i]; } } } LL querymx(LL x) { LL ret = x; ref(i, 63, 0) if ((ret ^ a[i]) > ret) ret ^= a[i]; return ret; } LL querymn(LL x) { LL ret = x; nmf(i, 0, 63) if ((ret ^ a[i]) < ret) ret ^= a[i]; return ret; } }; XORbasis B; #define int LL int n, m; vector<pair<int, int>> grh[50004]; bool vis[50004]; int val[50004]; void dfs(int u, int now) { vis[u] = 1; val[u] = now; for (auto [v, w] : grh[u]) { if (vis[v]) B.insert(now ^ val[v] ^ w); else dfs(v, now ^ w); } } void solve() { read(n, m); nmf(i, 1, m) { int ui, vi, wi; read(ui, vi, wi); grh[ui].emplace_back(vi, wi); grh[vi].emplace_back(ui, wi); } dfs(1, 0); write(B.querymx(val[n])); return; } signed main() { solve(); return 0; }
|