POJ 3710 无向图简单环树上删边
结论题,这题关键在于如何转换环,可以用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 无向图简单环树上删边的更多相关文章
- POJ.3710.Christmas Game(博弈论 树上删边游戏 Multi-SG)
题目链接 \(Description\) 给定n棵"树",每棵"树"的节点可能"挂着"一个环,保证没有环相交,且与树只有一个公共点. 两人轮 ...
- poj 3710 Christmas Game(树上的删边游戏)
Christmas Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1967 Accepted: 613 Des ...
- POJ Christmas Game [树上删边游戏 Multi-SG]
传送门 题意: 有N 个局部联通的图.Harry 和Sally 轮流从图中删边,删去一条边后,不与根节点相连的部分将被移走.Sally 为先手.图是通过从基础树中加一些边得到的.所有形成的环保证不共用 ...
- 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 ...
- zstu.4191: 无向图找环(dfs树 + 邻接表)
4191: 无向图找环 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 117 Solved: 34 Description 给你一副无向图,每条边有 ...
- HDU 5299 圆扫描线 + 树上删边
几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...
- webform(八)——LinQ简单增、删、改、查
一.简单介绍 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where ...
- LinQ简单增、删、改、查
一.简单介绍 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
随机推荐
- effective c++ 笔记 (23-25)
//---------------------------15/04/08---------------------------- //#23 宁以non_member.non_friend替换m ...
- Harbor私有镜像仓库无坑搭建
转载:https://k8s.abcdocker.com/kubernetes_harbor.html 一.介绍 Docker容器应用的开发和运行路不开可靠的镜像管理,虽然Docker官方也提供了公共 ...
- [转]An overview of Openvswitch implementation
This is NOT a tutorial on how to use openvswitch, this is for developers who want to know the implem ...
- PAT-1004 Counting Leaves
1004 Counting Leaves (30 分) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- fabric-sdk-container v1.0-beta 新增支持多服务节点
HyperLedger/Fabric SDK Docker Image 该项目在github上的地址是:https://github.com/aberic/fabric-sdk-container ( ...
- VMware10 安装centos6.7 设置NAT模式固定ip
https://www.cnblogs.com/yychnbt/p/5173761.html
- php OPcache
众所周知php是一种解释型语言,它的执行可分为如下几个流程: Scanning(Lexing) ,将PHP代码转换为语言片段(Tokens) Parsing, 将Tokens转换成简单而有意义的表达式 ...
- Python Pandas read_csv报错
为实现文本去重(将前面采集的数据进行两两对比删除重复),写了以下代码. #-*- coding: utf-8 -*-import pandas as pd inputfile = 'e:/data/H ...
- 云平台项目--学习经验--jsrender前端渲染模板
jsrender的好处:可以预先自定义一些固定的html标签,在需要显示数据的时候,可以直接传入真实的数据并显示在web页面中,避免了Js编写中的复杂过程:针对高性能和纯字符串渲染并优化,不需要依赖D ...
- Spring之事务操作(注解)
事务操作步骤: <!-- 第一步.配置事务管理器 --> <bean id="transactionManager" class="org.spring ...