zoukankan      html  css  js  c++  java
  • 51nod 1963 树上Nim

    这题还真就是树上玩 Nim...

    相关知识点就是阶梯博弈,具体可以康这里 →_→ PS:手动搜索阶梯博弈

    然后这题就转化为了多路径的阶梯博弈,这样的话咱定义根节点深度为 0,然后把所有奇数深度点的权值异或一下康康是不是 0 就好了

    但这里要注意别加边 dfs ,直接利用题目性质(fa[i]<i) O(n) 读入的同时得到深度就好了,咱就是加边dfs T 了一发....

    //by Judge
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #define Rg register
    #define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
    #define go(u) for(Rg int i=head[u],v=e[i].to;i;v=e[i=e[i].nxt].to)
    #define ll long long
    using namespace std;
    const int M=3e5+3;
    typedef int arr[M];
    #ifndef Judge
    #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    #endif
    char buf[1<<21],*p1=buf,*p2=buf;
    inline int read(){ int x=0,f=1; char c=getchar();
    	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    	for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
    } int n,ans; arr d;
    int main(){
    	int T=read();
    	while(T--){ n=read(),ans=0; Rg int x;
    		fp(i,1,n-1) x=read(),d[i]=d[x]^1;
    		fp(i,0,n-1){ x=read();
    			if(d[i]&1) ans^=x;
    		} puts(ans?"win":"lose");
    	} return 0;
    }
    
  • 相关阅读:
    web.xml配置详解
    oracle按时间创建分区表
    cron表达式详解
    临时表
    配置非安装版tomcat服务
    CodeForces 785 D Anton and School
    CodeForces 601B Lipshitz Sequence
    CodeForces 590C Three States BFS
    CodeForces 592D Super M DP
    CodeForces 507E Breaking Good 2维权重dij
  • 原文地址:https://www.cnblogs.com/Judge/p/11619821.html
Copyright © 2011-2022 走看看