结论题,这题关键在于如何转换环,可以用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. docker之容器管理

    一.docker常用的创建命令 [root@node03 ~]# docker create --help [root@node03 ~]# docker run --help OPTIONS说明: ...

  2. LeetCode-37.解数独

    编写一个程序,通过已填充的空格来解决数独问题. 一个数独的解法需遵循如下规则: 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 3x3 ...

  3. foreach 当被循环的变量为空时 不进入循环

    $a = []; foreach($a as $v){ echo 222; } //不会输出222 并且不会报错

  4. Redis学习笔记之底层数据结构

    1.简单动态字符串(simple dynamic string, SDS) 定义: struct sdshdr {        int len;//记录buf中使用的字节数量        int ...

  5. 2013337朱荟潼 Linux第二章读书笔记——从内核出发

    1.获取内核源码 1.1Git 分布式的:下载和管理Linux内核源代码: - 获取最新提交到版本树的一个副本 $ git clone git://git.kernel.org/pub/scm/lin ...

  6. 完善好的web项目(校园包车)

  7. 基于OVS的VLAN虚拟化简易实践方案

    基于OVS的VLAN虚拟化简易实践方案 前言 本实验基于ovs的vlan流表匹配,根据端口进行vlan标签插入.手工配置ovs,使其具有vlan虚拟化方案. 实验拓扑 ---- ---- | h1 | ...

  8. 利用mask-image蒙层编写异形头像

    需求:后台给了一个规规矩矩的头像,或圆或方,UI要求展示成水滴的形状.正在想到底如何实现的时候,不由自主去翻了鑫神的博客,正好找到了答案,窃喜(·_·) UI给的形状: 后台给的头像(忽略橙色背景色, ...

  9. Python进阶-配置文件

    一. 什么是配置文件?为什么要做配置文件? 将所有的代码和配置都变成模块化可配置化,这样就提高了代码的重用性,不再每次都去修改代码内部,这个就是我们逐步要做的事情,可配置化 二. 配置文件长啥样? 配 ...

  10. Django-项目配置

    目录 配置文件 数据库配置DATABASE - 指定MySQL数据库 数据库配置DATABASE - 指定SQL Server数据库 数据库配置DATABASE - 指定多个数据库 模版文件 静态文件 ...