结论题,这题关键在于如何转换环,可以用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. 使用python处理百万条数据分享(适用于java新手)

    1.前言 因为负责基础服务,经常需要处理一些数据,但是大多时候采用awk以及java程序即可,但是这次突然有百万级数据需要处理,通过awk无法进行匹配,然后我又采用java来处理,文件一分为8同时开启 ...

  2. 巧用cheerio重构grunt-inline

    grunt-inline是楼主之前写的一个插件,主要作用是把页面带了__inline标记的资源内嵌到html页面去.比如下面的这个script标签. <script src="main ...

  3. java Script复习总结

    一:基础知识 1.JavaScript语言的历史 l  早期名称:livescript l  开发公司:网景公司(netscape) 2.JavaScript语言的基本特点 l  基于对象 l  事件 ...

  4. PAT甲题题解-1096. Consecutive Factors(20)-(枚举)

    题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...

  5. RYU 灭龙战 second day(内容大部分引自网络)

    RYU 灭龙战 second day(内容大部分引自网络) 写好的markdown重启忘了保存...再写一次RLG 巨龙的稀有装备-RYU代码结构 RYU控制器代码结构的总结 RYU入门教程 RYU基 ...

  6. ubuntu18.04配置nvidia docker和远程连接ssh+远程桌面连接(三)

    ubuntu18.04配置nvidia docker和远程连接ssh+远程桌面连接(三) 本教程适用于想要在远程服务器上配置docker图形界面用于深度学习的用户. (三)配置远程桌面连接访问dock ...

  7. PHP 爬虫——QueryList

    前言: 来了个任务说要做个电影网站,要写个壳,数据直接从别人那扒.行吧!那就要学习下PHP爬虫了.占个博客,以后补充.http://study.querylist.cc/archives/6/ 之前开 ...

  8. 【Leetcode】33. Search in Rotated Sorted Array

    Question: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforeh ...

  9. 学习Java并发的课程

    https://www.javaspecialists.eu/courses/concurrency.jsp http://www.jconcurrent.com/ javaConcurrentAni ...

  10. Ubuntu17安装Jenkins

    Java安装 Jenkins基于Java, 所以需要先安装java. Linux下安装java只要配置java环境变量即可. 首先,解压java到相应目录,我一般习惯把安装的软件放到目录/usr/lo ...