【题目链接】

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. ADO.NET改进防注入

    static void Main1(string[] args) { //用户输入一个需要查询的条件 car表 Console.WriteLine("请输入"); string c ...

  2. lua的Metatables和Metamethods

    Metatable: lua中的每一个表都有其Metatable,默认情况下Metatable为nil.可通过setmetatable函数设置或者改变一个表的Metatable, 也可以通过getme ...

  3. JS网站图集相册特效

    JS网站图集相册特效是一款可以直接使用鼠标进行前后导航,也可以通过缩略图来切换图片. 在线演示本地下载

  4. 搭建eclipse的安卓开发环境(eclipse+jdk+adt+sdk)

    学校暑期大作业让用安卓写一个app,有两种方案(android stduio+sdk和eclipse+jdk+adt+sdk)折腾了几天发现还是后者好用,但是安装环境和下载真的是去了半条命,(不过由于 ...

  5. Caffe+UbuntuKylin14.04_X64+CUDA 6.5配置

    在编译Caffe的漫长过程中,经过了一个又一个坑,掉进去再爬出来,挺有趣的.对比原文有修改! LInux下配置安装:(本文档使用同一块NVIDIA显卡进行显示与计算, 如分别使用不同的显卡进行显示和计 ...

  6. 系统A一定会按照自我的样子改造世界

    A一定会按照自己的样子去构建系统A1,A1一定还会按照自己的样子去构建系统A1.1,A1.1一定还是会按照自我的样子去构建A1.1.1……我们编程,我们改造世界,我们的方向是被注定要朝着构建人造人的方 ...

  7. Android 将Android项目打包成aar文件

    参考资料:https://blog.csdn.net/csdn_mm/article/details/78364444

  8. Django_学生管理系统

    一. Django简易学生管理系统 1.在pycharm中创建工程student_manage_system,添加app:student_manage 2.配置静态文件:在工程项目目录下新建目录sta ...

  9. iframe嵌入的子页面如何刷新父窗口

    iframe中刷新父页面方法及一些按钮刷新代码集合[原创+转]2009-07-23 11:12a页面里iframe了个b页面,我想实现在b页面里一个按钮,一按就刷新a页面,也就是父页面,不是只刷新if ...

  10. HDU2147 - kiki's game 【巴什博弈】

    Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes th ...