惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
GbyAI
GbyAI
博客园 - 叶小钗
B
Blog
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
爱范儿
爱范儿
SecWiki News
SecWiki News
N
News and Events Feed by Topic
Y
Y Combinator Blog
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
云风的 BLOG
云风的 BLOG
博客园 - 聂微东
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
U
Unit 42
F
Full Disclosure
PCI Perspectives
PCI Perspectives
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
O
OpenAI News
S
Security Affairs
D
Docker
博客园 - Franky
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
Hugging Face - Blog
Hugging Face - Blog
TaoSecurity Blog
TaoSecurity Blog
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
N
News and Events Feed by Topic

博客园 - Mose

CS学习 NOI2002_ Galaxy银河英雄传说86 [Elite 2008 Dec USACO]Jigsaw Puzzles SGU 223 little kings BSOJ2772 状压DP BZOJ 3132(上帝造题的七分钟-树状数组求和+2D逆求和数组) 埃及分数 【区间DP】codevs3657 括号序列题解 ubuntu安装php-curl拓展 MIT挑战(如何在12个月内自学完成MIT计算机科学的33门课程|内附MIT公开课程资源和学习顺序 大白话Docker入门(一) Hexo博客搭建全解 代码查重工具sim virtual judge 本地部署方案 POJ题目分类推荐 (很好很有层次感) 解决Ubuntu下Sublime Text 3无法输入中文 [pascal入门]数组 [codecademy]fonts in css [codecademy]css Ubuntu录制gif动态图
[usaco]2013-jan Liars and Truth Tellers 真假奶牛
Mose · 2017-05-12 · via 博客园 - Mose
  • Description

约翰有N头奶牛,有一部分奶牛是真话奶牛,它们只说真话,而剩下的是假话奶牛,只说假话。有一天,约翰从奶牛的闲谈中陆续得到了M句话,第i句话出自第Xi头奶牛,它会告诉约翰第Yi头是一头真话奶牛还是假话奶牛。然而,约翰记性不好,他可能把这些话的内容记错了。请检查一下 约翰的记录是否会有矛盾,帮助他找到一个尽量大的K使得约翰记下的前K句话不矛盾。

  • Input Format

第一行:两个整数 N 和 M ,1 ≤ N ≤ 1000; 1 ≤ M ≤ 10000 
• 第二行到 M + 1 行:第 i + 1 行有两个整数:Xi 和 Yi,1 ≤ Xi, Yi ≤ N ,接下来有一个字符: 
– 如果是 T ,表示 Xi 说 Yi 是真话奶牛; 
– 如果是 L,表示 Xi 说 Yi 是假话奶牛;

  • Output Format

单个整数,即表示题目描述中的K

  • Sample Input

4 3 
1 4 L 
2 3 T 
4 1 T

  • Sample Output

2

  • Hint

解释 
前两句没有矛盾, 但第一句和第三句存在矛盾

sol:

题目说的是前k个。。

并查集判断,如果一个点为真或为假时它的祖先相同,则矛盾了。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
using namespace std;

const int N=2*1100,M=11000;
int n,m,fa[N];
char s[10];

int findfa(int x)
{
    if(fa[x]==x) return x;
    return findfa(fa[x]);
}

int main()
{
    // freopen("a.in","r",stdin);
    freopen("truth.in","r",stdin);
    freopen("truth.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=2*n;i++) fa[i]=i;
    int x,y,k=0,bk=1;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        scanf("%s",s);
        if(s[0]=='L')
        {
            fa[findfa(x)]=findfa(n+y);
            fa[findfa(n+x)]=findfa(y);
        }
        else 
        {
            fa[findfa(x)]=findfa(y);
            fa[findfa(n+x)]=findfa(n+y);
        }
        if(findfa(y)==findfa(n+y)) bk=0;
        if(bk) k++;
    }
    printf("%d\n",k);
    return 0;
}