【题目链接】

http://poj.org/problem?id=1

【算法】

并查集

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; struct Query
{
int l,r,op;
} q[]; int k,n,i,x,y,len;
int l[],r[],fa[],d[],a[];
char s[][]; inline int get_root(int x)
{
if (fa[x] == x) return x;
int f = get_root(fa[x]);
d[x] ^= d[fa[x]];
return fa[x] = f;
} int main()
{ scanf("%d%d",&k,&n);
for (i = ; i <= n; i++)
{
scanf("%d%d%s",&l[i],&r[i],&s[i]);
a[++len] = l[i] - ;
a[++len] = r[i];
}
sort(a+,a+len+);
len = unique(a+,a+len+) - a - ;
for (i = ; i <= n; i++)
{
q[i].l = lower_bound(a+,a+len+,l[i]-) - a;
q[i].r = lower_bound(a+,a+len+,r[i]) - a;
q[i].op = strcmp(s[i],"odd") == ? : ;
}
for (i = ; i <= * n; i++) fa[i] = i;
for (i = ; i <= n; i++)
{
x = get_root(q[i].l);
y = get_root(q[i].r);
if (x == y)
{
if ((d[q[i].l] ^ d[q[i].r]) != q[i].op)
{
printf("%d\n",i-);
exit();
}
} else
{
fa[x] = y;
d[x] = d[q[i].l] ^ d[q[i].r] ^ q[i].op;
}
}
printf("%d\n",n); return ; }

【POJ 1733】 Parity Game的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. 无序列表属性 隐藏方式 JS简介

    今天考试了,整理一下错题. 1.无序列表的属性 list-style 分为三小类 (1)list-style-type none:无标记. disc:实心圆(默认). circle:空心圆. squa ...

  2. hiho一下 第174周

    题目1 : Dice Possibility 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice ...

  3. Function 构造器及其对象、方法

    一.基础 Function 是一个构造器,能创建Function对象,即JavaScript中每个函数实际上都是Function 对象. 构造方法:  new Function ([arg1[, ar ...

  4. android黑科技系列——破解游戏之修改金币数

    我们在玩游戏的时候总是会遇到一些东东需要进行购买的,但是我们可能又舍不得花钱,那么我们该怎么办呢?那就是用游戏外挂吧!我们这里说的是Android中的游戏,在网上搜索一下移动端游戏外挂,可能会找到一款 ...

  5. vs2012编译boost_1_54_0

    在原文上进行了修改,我的环境是VS2012 ,在编译 注意事项:Boost 请慎用!微软太坑爹...且直接使用GitHub上的exe文件也可以,特定版本的只能自己编译了....汗!!! 原文地址:ht ...

  6. java中4种修饰符访问权限的区别及详解全过程

    java中4种修饰符访问权限的区别及详解全过程 http://jingyan.baidu.com/article/fedf0737700b3335ac8977ca.html java中4中修饰符分别为 ...

  7. Centos7 执行firewall-cmd –permanent –add-service=mysql报错“ModuleNotFoundError: No module named 'gi'”

    因为目前环境Python3.x与Python2.x版本并存,所以导致以上问题. 解决方法: 第一步,vim  /usr/bin/firewall-cmd, 将#!/usr/bin/python -Es ...

  8. 10件5G能实现,但4G不能做的事情

    10件5G能实现,但4G不能做的事情 从三星Galaxy S10 5G手机到OnePlus 7 Pro 5G手机以及更高版本,首批5G手机现已上市.5G网络时代的开启是从小范围内,如果你居住在可以使用 ...

  9. LCA-倍增法(写给自己看)

    LCA-倍增法 题目又做不下去来写题解了 算法思想 类似于ST表的思想维护dp[i][j]:节点i向上跳2^j高度的的节点 转移方程 \(dp[i][j]=dp[dp[i][j-1]][j-1]\)注 ...

  10. jQuery元素属性操作

    在jQuery中,用attr()方法来获取或者设置元素属性,removeAttr()方法用来删除元素属性. attr() 实例: var $para=$('p');//获取<p>节点 va ...