链接:

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的更多相关文章

  1. Parity game POJ - 1733 带权并查集

    #include<iostream> #include<algorithm> #include<cstdio> using namespace std; <& ...

  2. 【POJ1733】【带标记并查集】Parity game

    Description Now and then you play the following game with your friend. Your friend writes down a seq ...

  3. (并查集 建立关系)食物链 -- POJ-- 1182

    链接: http://poj.org/problem?id=1182 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  4. (并查集)The Suspects --POJ --1611

    链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  5. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  6. 并查集,是否成树,Poj(1308)

    思路: 对于每一条新的边的两个端点,是否是属于一颗树,要是的话,就不是一颗树.否则,就合并. 这里要注意的是,不能是森林,我这里WA了两次了.只不过在最后,查看每个节点的祖先是否是同一个就可以了. # ...

  7. 【转】并查集&MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...

  8. 【并查集】 不相交集合 - 并查集 教程(文章作者:Slyar)

    最近写了一个多星期的并查集,一瞬间贴出这么多解题报告,我想关于并查集的应用先告一段落吧,先总结一下. 在网上看到一篇关于并查集比较好的教程(姑且允许我这么说吧),不转过来是在可惜.献给爱学习的你 文章 ...

  9. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

随机推荐

  1. 关于eval()函数处理后台返回的json数据

    对于服务器返回的JSON字符串,如果jquery异步请求没做类型说明,或者以字符串方式接受,那么需要做一次对象化处理,方式不是太麻烦,就是将该字符串放于eval()中执行一次.这种方式也适合以普通ja ...

  2. 类定义,创建/销毁OC对象

    类定义 1 OC类分为2个文件,一个是.h文件,一个是.m文件: 2 .h文件存放类.函数声明: 3 .m文件类的具体实现: 4 类声明使用关键字@interface.@end来声明: 5 类实现使用 ...

  3. 关于时间查询的sql语句

    今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ...

  4. Zookeeper 注册中心

    一.Zookeeper的介绍 Zookeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用 ...

  5. update from

    update table1 set table1.column1 =(select table2.column1 from table2  where 关联条件) where exists(selec ...

  6. mongodb根据子项中的指标查找最小或最大值

    假设students集合中有这样的数据: { "_id" : 1, "name" : "Aurelia Menendez", "s ...

  7. eclipse使用MAVEN打包可执行的jar包

    1.新建maven工程 注意勾选 随便填一下 建好之后工程目录如下 新建测试类与工具类,主类很简单 工具类也很简单,就是初始化了日志 maven依赖包也只有一个log4j的jar <depend ...

  8. JAVA规则引擎JSR-94笔札

    JAVA规则引擎JSR-94笔札 JSR-94 是由JCP(Java Community Process)组织所制定的java规则引擎API的java请求规范.它主要定义了规则引擎在java运行时的一 ...

  9. .net 4.0的Lazy<T>方法,反射实现延迟加载。

    //自己山寨.public class YaLazy<T> { private bool _isValueCreated = false; public bool IsValueCreat ...

  10. Golang之hello,beego

    学习谢大神的beego记录 过程: 目录结构: 编译命令: go build -o myBeego.exe go_dev/day13/beego_example/main执行myBeego.exe即可 ...