• LuoGu P2420 让我们异或吧


    其实......这就是个SB题,本来看到这个题,和树上路径有关
    于是——我就欣喜地打了一个树剖上去,结果嘞,异或两遍等于没异或
    所以这题和LCA屁关系都没有,所以这题就是个树上DFS!!!!
    所以它为啥是绿的?不知道.....某谷地评分就是不能信
    于是就A了呗

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    
    const int N=1e5+5;
    
    struct edge{
    	int to,next,data;
    }e[(N<<1)];
    
    int n,tot,head[N];
    int Xor[N],m;
    
    inline void build(int u,int v,int w){
    	e[++tot].next=head[u];e[tot].to=v;
    	head[u]=tot;e[tot].data=w;return ;
    }
    
    inline void dfs(int cur,int anc){
    	for(int i=head[cur];i;i=e[i].next){
    		register int k=e[i].to;
    		if(k==anc) continue;
    		Xor[k]=Xor[cur]^e[i].data;
    		dfs(k,cur);
    	}
    	return ;
    }
    
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<n;++i){
    		register int u,v,w;
    		scanf("%d%d%d",&u,&v,&w);
    		build(u,v,w);build(v,u,w);
    	}
    	dfs(1,0);
    	scanf("%d",&m);
    	while(m--){
    		register int u,v;
    		scanf("%d%d",&u,&v);
    		printf("%d
    ",Xor[u]^Xor[v]);
    	}
    	return 0;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    Python之格式化unix时间戳
    Python简单的验证码生成
    Python字符串常用的一些东西
    PHP explode()函数
    PHP函数number_format()
    PHP简单的计算位数的函数
    python之列表推导式
    python之把列表当做队列使用
    python之列表操作的几个函数
    python之map函数
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/9830771.html
Copyright © 2020-2023  润新知