为什么会T啊,要死了
查看原帖
为什么会T啊,要死了
164883
Zigh_Wang楼主2022/6/13 14:55

T 7, 8, 9

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int MAXN = 5e4 + 5;
const int MAXM = 1e5 + 5;

int inpt()
{
	int x = 0, f = 1;
	char ch;
	for(ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
	if(ch == '-'){
		f = -1;
		ch = getchar();
	}
	do{
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return x * f;
}
ll inptll()
{
	ll x = 0, f = 1;
	char ch;
	for(ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
	if(ch == '-'){
		f = -1;
		ch = getchar();
	}
	do{
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return x * f;
}

int n, m;

int hd[MAXN], nxt[MAXM], to[MAXM], tot = 0;
ll w[MAXM];
void Add(int x, int y, ll z)
{
	nxt[++tot] = hd[x];
	hd[x] = tot;
	to[tot] = y;
	w[tot] = z;
}

ll lb[65];
ll ans = 0;
void Insert(ll a)
{
	int max_bit = __builtin_clzll(a);
	while(lb[max_bit] && a) {
		a ^= lb[max_bit];
		max_bit = __builtin_clzll(a);
		if(a == 0) {
			return ;
		}
	}
	lb[max_bit] = a;
}
void GetAns()
{
	for(int i = 4; i <= 63; i++) {
		ans = max(ans, ans ^ lb[i]);
	}
}

bool vis[MAXN];
ll dis[MAXN];
void dfs(int x, ll val)
{
	vis[x] = true;
	dis[x] = val;
	
	for(int i = hd[x]; i; i = nxt[i]) {
		int y = to[i];
		ll z = w[i];//有自环所以不能找到fa就走? 
		if(!vis[y]) {
			dfs(y, val ^ z);
		}else{
			Insert(val ^ z ^ dis[y]);
		}
	}
}

int main()
{
	n = inpt(), m = inpt();
	while(m--) {
		int x = inpt(), y = inpt();
		ll z = inptll();
		Add(x, y, z);
		Add(y, x, z);
	}
	
	dfs(1, 0);
	ans = dis[n];
	GetAns();
	
	printf("%lld", ans);
	
	return 0;
}
2022/6/13 14:55
加载中...