[USACO

2023-11-07

网址链接或者是链接

题目描述

After spending so much time around his cows, Farmer John has started to understand their language. Moreover, he notices that among his N cows ( 2 ≤ N ≤ 1000 2 \leq N \leq 1000 2N1000), some always tell the truth while others always lie.

FJ carefully listens to M statements (1 <= M <= 10,000) from his cows, each of the form “x y T”, meaning that “cow x claims cow y always tells the truth” or “x y L”, meaning that “cow x claims cow y always tells lies”.
Each statement involves a pair of different cows, and the same pair of cows may appear in multiple statements.

Unfortunately, FJ believes he might have written down some entries in his list incorrectly, so there may not be a valid way to designate each cow as a truth teller or a liar that is consistent with all the M statements on FJ’s list. To help FJ salvage as much of his list as possible, please compute the largest value of A such that there exists a valid way to designate each cow as a truth teller or a liar in a manner that is consistent with the first A entries in FJ’s list.

输入

  • Line 1: Two space-separated integers, N and M.
  • Lines 2…1+M: Each line is of the form “x y L” or “x y T”, describing a statement made by cow x about cow y.

输出

  • Line 1: The maximum value of A such that the first A entries in FJ’s list can be consistent with some assignment of “truth teller” or “liar” to the N cows.

样例输入

4 3
1 4 L
2 3 T
4 1 T

样例输出

2

提示

There are 4 cows and 3 statements. Cow 1 says that cow 4 lies, cow 2 says that cow 3 tells the truth, and cow 4 says that cow 1 tells the truth.Statements 1 and 3 cannot both be satisfied at the same time, but
statements 1 and 2 can be, if we let cows 1…3 tell the truth and cow 4 be a liar.

在思考这个题的时候,想到过之前做过的一道类似的题目,当时也做了总结:链接,这一类叫做拓展域并查集
对于这个题目:
首先我们可以知道,每个点都有两个属性,真或者是假
对于a b L的情况,我们可以知道{
这句话表达的意思是a说b假
结果会有两种,a真b假或者是a假b真
}
对于a b T的情况,我们可以知道{
这句话表达的意思是a说b真
结果会有两种,a真b真,a假b假
}
所以说这里我们就可以用并查集来维护每个点的真假,如果说同一个点出现了两个真假状态,那就是矛盾的情况

int n,m;
int fa[maxn];
void init() {
	for(int i=1; i<=2*n; i++) fa[i] = i;
}
int find(int x) {
	if(x == fa[x]) return x;
	else return fa[x] = find(fa[x]);
}
int main() {
	n = read,m = read;
	init();
	int x,y;
	char c;
	int flag = 1,ans = 0,pos = 0;
	for(int i=1; i<=m; i++) {
		scanf("%d %d %c",&x,&y,&c);
		if(c == 'L') {
			fa[find(n + x)] = find(y);
			fa[find(n + y)] = find(x);
		} else {
			fa[find(x)] = find(y);
			fa[find(n + x)] = find(n + y);
		}
		if(find(y) == find(n + y)) {
			flag = 0;
			pos = i-1;
		}
		if(flag) ans ++;
	}
//	assert(pos == flag);
	cout << ans << endl;
	return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

[USACO 的相关文章

随机推荐

  • Spring 事件发布机制

    目录 事件驱动 使用事件机制 Java 事件使用 Spring 事件使用 使用 Aware 不使用 Aware Spring 事件发布流程及源码解析 ApplicationEvent ApplicationListener 监听者注册 Ap
  • node常见面试题库

    node常见面试题库 1 检测系统中node版本号的指令是 node v 2 如何退出node执行环境 REPL环境 ctrl c c 3 node如何创建服务器 写出代码 var http require http var server
  • 合理设置的MTU值,解决“部分网站打不开”“上网速度慢”等问题,并且可以适当提升上网速度

    一般来讲 设计好本机的MTU值 可以解决 部分网站打不开 上网速度慢 的情况 但是如果你的共享主机或路由器的MTU设置有问题 有时问题仍然存或 或者出现网速过慢的情况 合理的设置路由器与本机的MTU值 就可以完全解决上述问题 使上网速度达到
  • AndroidJavaClass 和AndroidJavaClass

    很明显 AndroidJavaClass 就代表一个Java类 例如 com henry util 有一个静态方法 love 可以这样new AndroidJavaClass com henry util callstatic love 就
  • swagger mock文档服务器,通过 Swagger 定义自动生成 Mock 数据

    我最近的在做的项目是一个前后端分离的项目 前后端由不同的团队分别开发 并且前端的进度经常领先后端 这就意味着 当前端在开发一个新功能时 API 可能还没有准备好 不过 我们会先和后端先商议好 API Schema 然后使用 Mock 数据进
  • 使用PowerDNS实现内网DNS解析

    部署环境 公司内部安装powerdns实现局域网服务dns解析 避免通过ip访问 系统 CentOS 7 9 mysql版本 5 7 33 pdns版本 4 4 1 pdns recursor版本 4 4 2 PowerDNS admin版
  • ARTS挑战打卡的100天,我学到了这些

    前言 知道ARTS打卡计划是来源于陈皓的极客时间教程 在大学期间就知道了陈皓 左耳朵耗子 骨灰级程序员 差不多就是看着他的博客成长 后来在极客时间上发现了他的课程 就买下来了 现在学习了75 过程中发现了ARTS打卡计划 一直不敢尝试 一个
  • 第二课:变量和数据类型

    第二课 变量和数据类型 一 了解什么是变量 为什么需要它 1 计算机中的内存分类 1 RAM 运行时存储 我们的计算机程序在运行的时候 数据就会临时存储在RAM中 如果不持久化 或着突然断电 它的数据就丢失了 2 ROM 只读存储 持久化存
  • css伪元素实现方框上面打钩

    html p class skill three con item frame p css skill three con item frame width 36px height 36px background transparent b
  • 深入浅出SQL(7)-ALTER

    该系列文章系个人读书笔记及总结性内容 任何组织和个人不得转载进行商业活动 ALTER 改写历史 使用ALTER命令 可以修改表 对其套用新的设计方法 且不会影响现有数据 本章还会学到规范化的意义 我们要规范化我们的表 由于重新建了本地数据库
  • unity2d物理系统在安卓闪退的坑

    记录下2d物理系统安卓闪退的坑 之前的2d横版动作游戏和现在的幸存者游戏都出现过同样的问题 通过一步一步的排查 确定是Unity Project Setting Physics 2D Auto Sync Transfroms 这里勾选上的问
  • c盘清理

    https jingyan baidu com article ea24bc39ebefadda62b33180 html 转载于 https www cnblogs com zach0812 p 11557586 html
  • 神舟笔记本进入BIOS的方法

    最近整了一个i9 8950h的神舟笔记本 默认预装的是windows 10 总结一下进入BIOS的方法 方法一 重启电脑 黑屏的时候 不断按F2键 这个方法的优点是操作简单 缺点是有时候会进不去 直接进入桌面 方法二 系统设置 gt 更新和
  • IDEA工作常用快捷键

    ide快捷键 Intellij IDEA 移动光bai标du到行尾的快捷键是End Intellij IDEA 移动光标到行首的快捷键是Home Home End键的意思是开头 结尾 在记事dao本或word等其他文本工具中也有同样的效果
  • Java的Integer.valueOf()初窥

    前言 今天在做题时 碰到了一道选择题 就是关于Integer valueOf 的知识 题目如下 A System out println i01 i02 B System out println i01 i03 C System out p
  • js string转json有斜杠_详解json串反转义(消除反斜杠)

    JSon串在被串行化后保存在文件中 读取字符串时 是不能直接拿来用JSON parse 解析为JSON 对象的 因为它是一个字符串 不是一个合法的JSON对象格式 例如下面的JSON串保存在文件中 读出来不能直接解析 resourceId
  • C++类模板的特化(三)

    本文主要介绍类模板的特化 局部特化和缺省模板实参 1 类模板的特化 类模板的特化 Class Template Specialization 是指为特定的模板参数提供自定义实现的过程 通过特化 我们可以针对某些特定的类型或条件提供不同的行为
  • Java分页工具类

    通用分页工具类 import java io Serializable import java util List b 分页通用类 b author hcw param
  • 自定义同步器

    自定义同步器 假如你想要实现一个自定义同步器 官方推荐的做法是将继承了AQS类的子类作为自定义同步器的内部类 而自定义同步器中相关的操作只需代理成子类中对应的方法即可 往下用一个简单的例子看看如何实现自己的锁 由于同步器被分为两种模式 独占
  • [USACO

    网址链接或者是链接 题目描述 After spending so much time around his cows Farmer John has started to understand their language Moreover