POJ 3710 Christmas Game
来源:互联网 发布:淘宝联盟网站推广备案 编辑:程序博客网 时间:2024/05/20 23:59
POJ 3710 Christmas Game
图的删边游戏:
由于这个图比较特殊,我们推出如果环是奇环,则相当于加一条边,偶数环就相当于删除环,变成一个点。
不会缩环的默默YY了一个多小时才勉强搞定。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<set>#include<queue>#include<map>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define CLR(a) memset((a),0,sizeof((a)))#define pb push_back#define mp make_pair#define ins insert#define F first#define S second#define bug puts("Oh Here!");#define nMax 2001#define oo 0x7fffffff#define eps 1e-8#define LL long long#define Vec vector<int>#define Pai pair<int,int>class tree{public: int first[nMax],to[nMax],nxt[nMax],e,sg[nMax],vis[nMax],in[nMax]; int dfn[nMax],low[nMax],olen; int adj[510][510]; int n,root; void clear(){memset(first,-1,sizeof(first));e=0;CLR(adj);} void addadge(int ,int ); void rebuild(); void dfs(int ,int ,int ); int dfs(int ); int sovle();};void tree::addadge(int u,int v){ to[e]=v;nxt[e]=first[u];first[u]=e;e++; to[e]=u;nxt[e]=first[v];first[v]=e;e++;}int tree::dfs(int u){ sg[u]=0; vis[u]=1; for(int i=first[u];i!=-1;i=nxt[i])if(!in[to[i]] && !vis[to[i]]){ sg[u] ^= (dfs(to[i])+1); } return sg[u];}void tree::dfs(int u,int fa,int dep){ //printf("%d ->\n",u); dfn[u]=low[u]=dep; vis[u]=1; for(int i=first[u],v;i!=-1;i=nxt[i]){ v=to[i]; if(vis[v]==1 && v!=fa){ olen = dfn[v]-dfn[u]+1; low[u]=min(low[u],dfn[v]); } if(vis[v]==1 && v==fa && adj[u][v]>1){ olen = 2; low[u]=min(low[u],dfn[v]); } if(!vis[v]){ dfs(v,u,dep+1); low[u]=min(low[u],low[v]); } } if(low[u]<dfn[u]){ in[u]=1; } if(low[u]==dfn[u]){ if(olen&1){ addadge(u,++n); olen=0; } } vis[u]=2; //printf("<-\n");}void tree::rebuild(){ CLR(in); CLR(vis); olen=0; dfs(root,-1,0);}int tree::sovle(){ int m; scanf("%d%d",&n,&m); clear(); root=1; for(int i=0,u,v;i<m;i++){ scanf("%d%d",&u,&v); if(adj[u][v]==0) addadge(u,v); adj[u][v]++; adj[v][u]++; } rebuild(); //FOR(i,1,n) printf("%d %d\n",i,in[i]); CLR(vis); dfs(root); //printf("--%d\n",sg[root]); return sg[root];}tree p;int main(){#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin);#endif int t; while(~scanf("%d",&t)){ int sg=0; while(t--) sg ^= p.sovle(); printf("%s\n",sg?"Sally":"Harry"); } return 0;}
- POJ 3710 Christmas Game
- POJ 3710 Christmas Game
- poj 3710——Christmas Game
- [删边游戏] POJ 3710 Christmas Game
- POJ 3710 Christmas Game(Tarjan+博弈SG函数)
- poj 3710 Christmas Game (树形删边游戏)
- poj 3710 Christmas Game(博弈 无向图删边游戏)
- POJ 3710 Christmas Game 树上删边博弈,压缩环
- POJ 3710 Christmas Game (Tarjan求连通分量+树形博弈删边游戏)
- POJ 3710 Christmas Game 无向图删边 经典的删边游戏 Tarjan缩点
- Big Christmas Tree POJ
- POJ 3160 Father Christmas flymouse
- poj 3160 Father Christmas flymouse
- Poj 3013 Big Christmas Tree
- poj 3013 big christmas tree
- poj 3160 Father Christmas flymouse
- POJ - 3013 Big Christmas Tree
- POJ 3160 Father Christmas flymouse
- mfc视频教程
- wordpress 更换主题
- 程序员必知(三):一分钟知道URI编码(encodeURI)
- Hdu2036-求多边形面积
- xcode4.3.2 下制作ios的framework 库
- POJ 3710 Christmas Game
- mysql中如果数据记录不存在,则插入,否则更新该数据记录的办法
- SEO----基本知识
- MySQL定时计划任务
- 恢复已掉排名办法
- VS2008的SVN插件AnkhSVN使用详解
- MySQLdb 连接Mysql 数据库出错解决
- opencv2中的程序
- Araxis Merge 文件夹对比的时候过滤隐藏目录(.svn)