bzoj2115

这题。。。不看看题解谁tm想得到标算!看了题解。。。谁tm不会写。。。唯一有点技巧性的就是生成树的时候判环那个操作(因为一个点只要被访问了两次那么两条路径一xor必然是一个环,不是环的部分是重合的所以抵消了)其他的话。注意一下di是longlong 我因为不喜欢看那么长的题目所以看的都是简化版题目没能注意到被卡了好几发

#include <cstdio>  
#include <cmath>  
#include <ctime>  
#include <string>  
#include <cstring>  
#include <cstdlib>  
#include <iostream>  
#include <algorithm>  
  
#include <set> 
#include <stack>  
#include <queue>  
#include <vector>  
#include<map>
#include<list>
 
#define pb push_back 
#define lb lower_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x)  
#define Abs(x) ((x) > 0 ? (x) : (-(x)))  
#define forup(i,a,b) for(int i=(a);i<=(b);i++)  
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)  
#define ls(a,b) (((a)+(b)) << 1)  
#define rs(a,b) (((a)+(b)) >> 1)  
#define getlc(a) ch[(a)][0]  
#define getrc(a) ch[(a)][1]  
  
#define maxn 400005 
#define maxm 100005 
#define INF 1070000000  
using namespace std;  
typedef long long ll;  
typedef unsigned long long ull;  
  
template<class T> inline  
void read(T& num){  
    num = 0; bool f = true;char ch = getchar();  
    while(ch < '0' || ch > '9') { if(ch == '-') f = false;ch = getchar();}  
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}  
    num = f ? num: -num;  
} 
int out[100]; 
template<class T> inline 
void write(T x,char ch){ 
 if (x==0) {putchar('0'); putchar(ch); return;} 
 if (x<0) {putchar('-'); x=-x;} 
 int num=0; 
 while (x){ out[num++]=(x%10); x=x/10;} 
 fordown(i,num-1,0) putchar(out[i]+'0'); putchar(ch); 
} 
/*==================split line==================*/

int n,m;
 struct Edge
 {int to;
 ll len;};vector<Edge> g[maxn];
 ll d[maxn];
 vector<ll> a;
 bool vis[maxn];

void dfs(int x)
{vis[x]=1;
   for(int i=0;i<g[x].size();i++)
   {   int v=g[x][i].to;
      if(!vis[v])
         {  d[v]=d[x]^g[x][i].len;
		    dfs(v);
		 
		 }
   	  else
		 { a.pb(d[x]^g[x][i].len^d[v]);
		  } 
   }
	 
}
void guass()
{   int r=0;
   for(int i=62;i>=0;i--)
   {
    for(int j=r;j<a.size();j++)
    {if(a[j]>>i&1)
       {swap(a[r],a[j]);
        break;
	   }  
    } 
	   if(a[r]>>i&1)   {}
	    else continue;
	   for(int j=0;j<a.size();j++)
	   { if(j!=r&&a[j]>>i&1) a[j]=a[j]^a[r];
		}
		r++; 
   }
}


int main()
{  read(n);read(m);
   forup(i,1,m)
    { int x,y;ll z; read(x),read(y),read(z);
       g[x].pb((Edge){y,z});g[y].pb((Edge){x,z});
	}
	dfs(1);
	guass();
	ll ans=d[n];
	for(int i=0;i<a.size();i++)
	 {  ans=max(ans,ans^a[i]);
	  } 
	write(ans,'\n');
	return 0;
}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值