zoukankan      html  css  js  c++  java
  • BZOJ 2115 [Wc2011] Xor

    题解:xor最大路径一定是几个环加上从1到n的路径

    环用tarjan处理

    最大xor和用线性基处理

    喵啊

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    typedef long long Lint;
    const int maxn=50007;
    
    int n,m;
    Lint ans;
    
    int cntedge;
    int head[maxn];
    int to[maxn<<2],nex[maxn<<2];
    Lint dist[maxn<<2];
    void Addedge(int x,int y,Lint z){
    	nex[++cntedge]=head[x];
    	to[cntedge]=y;
    	dist[cntedge]=z;
    	head[x]=cntedge;
    }
    
    Lint p[maxn];
    int dfsclock;
    int pre[maxn],lowlink[maxn];
    Lint depth[maxn];
    void Dfs(int u,int fa){
    	pre[u]=lowlink[u]=++dfsclock;
    	
    	for(int i=head[u];i;i=nex[i]){
    		if(to[i]==fa)continue;
    		if(!pre[to[i]]){
    			depth[to[i]]=depth[u]^dist[i];
    			Dfs(to[i],u);
    			lowlink[u]=min(lowlink[u],lowlink[to[i]]);
    		}else{
    			lowlink[u]=min(lowlink[u],pre[to[i]]);
    			Lint x=depth[u]^depth[to[i]]^dist[i];
    			for(int j=62;j>=1;--j){
    				if(x&(1LL<<(j-1))){
    					if(p[j]){
    						x^=p[j];
    					}else{
    						p[j]=x;break;
    					}
    				}
    			}
    		}
    	}
    }
    
    int main(){
    	scanf("%d%d",&n,&m);
    	while(m--){
    		int x,y;Lint z;
    		scanf("%d%d%lld",&x,&y,&z);
    		Addedge(x,y,z);Addedge(y,x,z);
    	}
    	
    	Dfs(1,0);
    	ans=depth[n];
    	for(int j=62;j>=1;--j){
    		if((ans^p[j])>ans)ans=(ans^p[j]);
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    

      

    自己还是太辣鸡了
  • 相关阅读:
    [LOJ#6284.数列分块入门8] ODT(珂朵莉树)解法
    [CF Contest] Sum of Round Numbers 题解
    基础数论记录
    [CF Contest] Kana and Dragon Quest game 题解
    hexo上怎么写博客
    keepalived的部署
    python局部和全局变量
    python发送邮件
    lamp架构的部署
    rayns数据同步
  • 原文地址:https://www.cnblogs.com/zzyer/p/8456383.html
Copyright © 2011-2022 走看看