[POJ3710] Delete and play games on restricted charts in the Christmas Game (tree-based deletion and Game evolution 1) and poj3710christmas

Source: Internet
Author: User

[POJ3710] Delete and play games on restricted charts in the Christmas Game (tree-based deletion and Game evolution 1) and poj3710christmas

Reprinted please indicate the source: http://blog.csdn.net/vmurder/article/details/42671885
In fact, I feel that the original traffic volume is a little less uncomfortable than unauthorized piracy by 233...

Question:

A tree chart is followed by a root node. The two sides take turns to delete edges. They cannot delete edges.

Edge deletion restriction: Only edges connected to 1 can be deleted.

Tree chart restrictions:

It is a tree first, and then some points may contain a ring

Original description: The first graph is a tree with some simple rings, and any side is at most on a polygon. Each polygon can have at most one node on the master tree.


Here is the address of the essay:

Shijiazhuang No. 2 Middle School Jia Zhihao --

Summary of combined games-several extensions and changes to SG games

Http://wenku.baidu.com/link? Url = BV3xf05i4YyrBqgEnkDnTNxeKf85irWoLLY_uVki2aa-nGL6h2yrEww8FKx2DoTq5cxe4NKF2Sl3tj4kvhNvknRbscpdCtKPY3hKDPyZlhW


Code:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 105#define M 1500using namespace std;struct KSD{int v,next;}e[M];int head[N],cnt,newnode,TOT;inline void add(int u,int v){e[++TOT].v=v;e[TOT].next=head[u];head[u]=TOT;}int n,m,map[N][N];int dfn[N],low[N];int stk[N],top;int flag[N];void init(){cnt=TOT=top=0;memset(head,0,sizeof head);memset(map,0,sizeof(map));memset(dfn,0,sizeof(dfn));memset(flag,0,sizeof(flag));memset(stk,0,sizeof(stk));}void tarjan(int x,int p){int i,u,v,temp;low[x]=dfn[x]=++cnt;stk[++top]=x;for(i=1;i<=n;i++)if(map[x][i]&&i!=p){if(!dfn[i]){tarjan(i,x);low[x]=min(low[x],low[i]);if(dfn[x]<=low[i]){temp=++top;while(stk[--top]!=x);if((temp-top==2&&map[x][i]==1)||(temp-top)&1){if(!flag[x])flag[x]=u=++newnode;else u=flag[x];if(!flag[i])v=++newnode;else v=flag[i];add(u,v);}}}else low[x]=min(low[x],dfn[i]);}return ;}int SG(int x,int p){int i,v,sg=0;for(i=head[x];i;i=e[i].next){v=e[i].v;if(v==p)continue;sg^=(SG(v,x)+1);}return sg;}int main(){//freopen("test.in","r",stdin);int i,k,T,a,b;while(scanf("%d",&T)!=EOF){for(k=0;T--;){scanf("%d%d",&n,&m);init();for(i=1;i<=m;i++){scanf("%d%d",&a,&b);map[a][b]++,map[b][a]++;}cnt=0;flag[1]=newnode=1;tarjan(1,0);k^=SG(1,0);}//printf("%d\n",k);if(k)puts("Sally");else puts("Harry");}return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.