【题目链接】

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. HTML5 audio 如何实现播放多个MP3音频

    <audio>标签是HTML5中的新标签,定义声音用于嵌入音频内容,比如音乐或其他音频流.用的比较多音频格式是.mp3. <audio>标签常用属性如下表 属性 值 描述 au ...

  2. JavaScript函数传参

    函数传参一: <html> <head> <meta charset="utf-8"> <title>无标题文档</title ...

  3. mysql 主从错误情况与原因

    mysql 主从错误情况1,master 上删除一条记录是从库报错 找不到该记录引起原因:master出现宕机或者从库已经删除.解决方案:stop slave;set global sql_slave ...

  4. 安装typescript开发环境

    参考文档: http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html 有两个方式 : 1.安装vs 2017,安 ...

  5. UVa 1583 Digit Generator WA

    #include<stdio.h> int main() { long int n,i,s=0; while(scanf("%d",&n)!=EOF) { in ...

  6. 图片放大不失真软件PhotoZoom如何使用?

    PhotoZoom可以将我们一些过于像素低的照片可以无失真放大,那么PhotoZoom是如何实现无失真照片放大的呢? 以上图像中的编号表示每个步骤应操作的位置. 单击“打开”,并选择您想调整大小的图像 ...

  7. setTimeout()传带有参数的函数

    w3cshool里的解释:setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,语法:setTimeout(code,millisec). 也就是说,第一个参数可以是字符串形式的Ja ...

  8. jsoup解析页面

    package com.java.jsoup; /** * jsoup解析网页 * @author nidegui * @version 2019年4月29日 下午5:12:02 * */ impor ...

  9. pip是用代理

    内网访问外网时,需要通过vpn访问,但是pip貌似不能是用vpn访问外网.直接度娘: windows下: set http_proxy=http://代理服务器:端口 不行可以试试下面的: set h ...

  10. Iterator和for...of

    Iterator和for...of 什么是Iterator ES6中的Map 和 Set ,再加上之前的数组和对象,这样就有了四种数据集合,用户可以组合使用它们,定义自己的数据结构.这时,我们就需要一 ...