结论题,这题关键在于如何转换环,可以用tarjan求出连通分量后再进行标记,也可以DFS直接找到环后把点的SG值变掉就行了

/** @Date    : 2017-10-23 19:47:47
* @FileName: POJ 3710 简单环 树上删边 DFS.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e3 + 20;
const double eps = 1e-8; struct node{
int nxt, to;
}edg[N*2]; int vis[N];
int head[N*2];
int tot;
int st[10010], top; int sg[N]; void init()
{
MMG(head);
MMG(vis);
MMF(sg);
tot = top = 0;
} inline void add(int x, int y)
{
edg[tot].nxt = head[x];
edg[tot].to = y;
head[x] = tot++;
} void dfs(int x, int pre)
{
st[++top] = x;
vis[x] = 1;
int flag = 0;
for(int i = head[x]; ~i; i = edg[i].nxt)
{
if(edg[i].to == pre && !flag)
{
flag = 1;
continue;
}
if(vis[edg[i].to] == 1)
{
int nw = st[top];
int cnt = 1;
while(nw != edg[i].to)
vis[nw] = 0, nw = st[--top], cnt++;
if(cnt & 1)//奇数环变边
sg[edg[i].to] ^= 1;
}
else if(vis[edg[i].to] == -1)
{
dfs(edg[i].to, x);
if(vis[edg[i].to])
sg[x] ^= sg[edg[i].to] + 1;
}
}
if(vis[x])
top--;
}
int main()
{
int T;
while(cin >> T){//多组样例233
int ans = 0;
while(T--)
{
int n, m;
scanf("%d%d", &n, &m);
init();
for(int i = 1; i <= m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
dfs(1, -1);
ans ^= sg[1];
}
printf("%s\n", ans?"Sally":"Harry");
}
return 0;
}

POJ 3710 无向图简单环树上删边的更多相关文章

  1. POJ.3710.Christmas Game(博弈论 树上删边游戏 Multi-SG)

    题目链接 \(Description\) 给定n棵"树",每棵"树"的节点可能"挂着"一个环,保证没有环相交,且与树只有一个公共点. 两人轮 ...

  2. poj 3710 Christmas Game(树上的删边游戏)

    Christmas Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1967   Accepted: 613 Des ...

  3. POJ Christmas Game [树上删边游戏 Multi-SG]

    传送门 题意: 有N 个局部联通的图.Harry 和Sally 轮流从图中删边,删去一条边后,不与根节点相连的部分将被移走.Sally 为先手.图是通过从基础树中加一些边得到的.所有形成的环保证不共用 ...

  4. Codeforces Round #143 (Div. 2) E. Cactus 无向图缩环+LCA

    E. Cactus   A connected undirected graph is called a vertex cactus, if each vertex of this graph bel ...

  5. zstu.4191: 无向图找环(dfs树 + 邻接表)

    4191: 无向图找环 Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 117  Solved: 34 Description 给你一副无向图,每条边有 ...

  6. HDU 5299 圆扫描线 + 树上删边

    几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...

  7. webform(八)——LinQ简单增、删、改、查

    一.简单介绍 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where ...

  8. LinQ简单增、删、改、查

    一.简单介绍 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where ...

  9. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

随机推荐

  1. EF Core 新特性——Owned Entity Types

    Owned Entity Types 首先owned entity type是EF Core 2.0的新特性. 至于什么是owned entity types,可以先把他理解为EF Core官方支持的 ...

  2. PAT甲题题解-1081. Rational Sum (20)-模拟分数计算

    模拟计算一些分数的和,结果以带分数的形式输出注意一些细节即可 #include <iostream> #include <cstdio> #include <algori ...

  3. eclipse实现热部署和热启动

    不用每次修改一个class文件就要重启tomcat这么麻烦: http://blog.csdn.net/fuzhongyu2/article/details/52073050

  4. 铁大快捷记账Alpha版使用说明书

    一. 引言 (1) 编写目的 (2) 参考资料 (3) 术语和缩写词 二. 网站概述 (1) 网站用途 (2) 网站运行 三. 网站使用过程 (1)网站登录 (2) 功能说明 一.引言 (1)编写目的 ...

  5. Windows 防火墙出站 入站规则简单说明

    1. Windows防火墙其实比linux的iptabels 要好用一些. 打开设置方式: 运行->输入control即可 选择系统和安全 2.win2019 以及改名字了 现在是 window ...

  6. [转帖][Bash Shell] Shell学习笔记

    [Bash Shell] Shell学习笔记 http://www.cnblogs.com/maybe2030/p/5022595.html  阅读目录 编译型语言 解释型语言 5.1 作为可执行程序 ...

  7. power shell 常用查询-查看操作系统信息

    https://technet.microsoft.com/en-us/library/dd367892.aspx 首推使用 Get-Counter 该函数下可以把现有的电脑监控统计数据 直接提取出来 ...

  8. maven的pom.xml举例

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  9. python自动化之爬虫原理及简单案例

    [爬虫案例]动态地图里的数据如何抓取:以全国PPP综合信息平台网站为例  http://mp.weixin.qq.com/s/BXWTf5hmq8vp91ZvgaphEw [爬虫案例]动态页面的抓取! ...

  10. java 堆和栈二

    1.数组 整数默认初始化值0 浮点数默认初始化值0.0 布尔类型默认初始化值false 字符类型默认初始化值\u0000 [I@7852e922 [有几个代表是几维数组 I代表是Int类型 @固定格式 ...