(并查集 建立关系)Parity game -- POJ -1733
链接:
http://poj.org/problem?id=1733
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/H
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std; #define N 110
#define oo 0xfffffff map<int, int>f; ///f[i]=x, i是int类型的,x也是int类型的
map<int, int>r;
int n, m; int Find(int x)
{
if(!f[x])
return x;
int k=f[x];
f[x]=Find(f[x]);
r[x]=(r[x]+r[k])%; return f[x];
} int main()
{
while(scanf("%d", &n)!=EOF)
{
scanf("%d", &m);
int i, a, b, fa, fb, ans=, flag=;
char s[N]; for(i=; i<=m; i++)
{
int num=;
scanf("%d%d%s", &a, &b, s);
a--; if(strcmp(s, "odd")==)
num=; fa=Find(a), fb=Find(b);
if((a< || a>=n) || (fa==fb && (r[a]+num)%!=r[b]))
flag=;
if(flag==)
continue;
if(fa!=fb)
{
f[fa]=fb;
r[fa]=(r[b]-(r[a]+num)%+)%;
}
ans++;
}
printf("%d\n", ans);
}
return ;
}
(并查集 建立关系)Parity game -- POJ -1733的更多相关文章
- Parity game POJ - 1733 带权并查集
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; <& ...
- 【POJ1733】【带标记并查集】Parity game
Description Now and then you play the following game with your friend. Your friend writes down a seq ...
- (并查集 建立关系)食物链 -- POJ-- 1182
链接: http://poj.org/problem?id=1182 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- (并查集)The Suspects --POJ --1611
链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- 并查集,是否成树,Poj(1308)
思路: 对于每一条新的边的两个端点,是否是属于一颗树,要是的话,就不是一颗树.否则,就合并. 这里要注意的是,不能是森林,我这里WA了两次了.只不过在最后,查看每个节点的祖先是否是同一个就可以了. # ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- 【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)
最近写了一个多星期的并查集,一瞬间贴出这么多解题报告,我想关于并查集的应用先告一段落吧,先总结一下. 在网上看到一篇关于并查集比较好的教程(姑且允许我这么说吧),不转过来是在可惜.献给爱学习的你 文章 ...
- 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil
题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...
随机推荐
- 【342】Linear Regression by Python
Reference: 用scikit-learn和pandas学习线性回归 首先获取数据存储在 pandas.DataFrame 中,获取途径(CSV 文件.Numpy 创建) 将数据分成 X 和 y ...
- GitLab CI 之 Java HelloWrold
问题描述 测试人员想在gitalb上跑 JUnit项目,也就是java代码. 听到这个之后,我当时都懵了,我他妈gitlab的runner是为运行.net core 安装的呀.后来一想,是我错了,我用 ...
- Java Magic. Part 2: 0xCAFEBABE
Java Magic. Part 2: 0xCAFEBABE @(Base)[JDK, magic, 黑魔法] 转载请写明:原文地址 英文原文 系列文章: -Java Magic. Part 1: j ...
- Spring,Hibernate 集成解决多hbm.xml文件繁多的方案
开发一个大一点的项目有很多的hbm.xml文件,有时候上百个也不稀奇,如果用 <property name="mappingLocations"> <list&g ...
- python中迭代问题
迭代list的时候不能修改这个list,否则,可能会出错. numbers=[1,0,3,5,0] numbers.sort() print(numbers) print('************* ...
- 迭代删除元素 并发bug 低级错误
方法一:HashMap<String, Integer> myHashMap = new HashMap<>();myHashMap.put("1", 1) ...
- 调试PHP如何让浏览器提示错误
php.ini中的display_errors的值改为On:或者php代码页顶部加上ini_set("display_errors", "On"); error ...
- Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied.
访问路径被拒绝 我解决了这个设置: IIS>应用程序池> [您的站点]>高级设置...>标识>内置帐户> LocalSystem
- UVa 10763 Foreign Exchange(map)
Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...
- 两个应用之间传递广播的规则 Broadcast
sendBroadcast(new Intent(Config.ACTION_PRINT),”com.qf.permission.print”);先判断应用有没有对应的权限 再去判断有没有对应的act ...