开 O2 TLE 0pts,不开 AC
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 50010, M = 2e5 + 10;
int n, m;
LL ans;
vector<LL> a;
int h[N], ne[M], e[M], idx;
LL w[M];
void add(int a, int b, LL c)
{
e[++idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx;
}
bool vis[N];
LL s[N];
bool dfs(int x)
{
vis[x] = 1;
for(int i = h[x]; i; i = ne[i])
{
int j = e[i];
if(vis[j])
{
if(w[i] ^ s[x] ^ s[j])
a.push_back(w[i] ^ s[x] ^ s[j]);
}
else
{
s[j] = s[x] ^ w[i];
dfs(j);
}
}
}
void gauss()
{
for(int i = 60, j = 0; ~i && j < a.size(); i--)
{
for(int k = j; k < a.size(); k++)
if(a[k] >> i & 1)
{
swap(a[j], a[k]);
break;
}
if(~a[j] >> i & 1) continue;
for(int k = 0; k < a.size(); k++)
if(k != j && a[k] >> i & 1) a[k] ^= a[j];
j++;
}
}
int main()
{
cin >> n >> m;
for(int i = 1, a, b; i <= m; i++)
{
LL c;
scanf("%d%d%lld", &a, &b, &c);
add(a, b, c), add(b, a, c);
}
dfs(1);
sort(a.begin(), a.end(), greater<LL>());
a.erase(unique(a.begin(), a.end()), a.end());
gauss();
ans = s[n];
for(LL i : a)
if((ans ^ i) > ans) ans ^= i;
cout << ans << endl;
return 0;
}