Mahmoud and a Dictionary codeforces396 div2 D

MOS五类漏电流与优化策略 分析了五种主要漏电流机制:1)反偏结泄漏,由PN结热激发和隧 阅读详情

D. Mahmoud and a Dictionary
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.

He know that if two words have a relation between them, then each of them has relations with the words that has relations with the other. For example, if like means love and love is the opposite of hate, then like is also the opposite of hate. One more example: if love is the opposite of hate and hate is the opposite of like, then love means like, and so on.

Sometimes Mahmoud discovers a wrong relation. A wrong relation is a relation that makes two words equal and opposite at the same time. For example if he knows that love means like and like is the opposite of hate, and then he figures out that hate means like, the last relation is absolutely wrong because it makes hate and like opposite and have the same meaning at the same time.

After Mahmoud figured out many relations, he was worried that some of them were wrong so that they will make other relations also wrong, so he decided to tell every relation he figured out to his coder friend Ehab and for every relation he wanted to know is it correct or wrong, basing on the previously discovered relations. If it is wrong he ignores it, and doesn’t check with following relations.

After adding all relations, Mahmoud asked Ehab about relations between some words based on the information he had given to him. Ehab is busy making a Codeforces round so he asked you for help.

Input
The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations.

The second line contains n distinct words a1, a2, …, an consisting of small English letters with length not exceeding 20, which are the words in the dictionary.

Then m lines follow, each of them contains an integer t (1 ≤ t ≤ 2) followed by two different words xi and yi which has appeared in the dictionary words. If t = 1, that means xi has a synonymy relation with yi, otherwise xi has an antonymy relation with yi.

Then q lines follow, each of them contains two different words which has appeared in the dictionary. That are the pairs of words Mahmoud wants to know the relation between basing on the relations he had discovered.

All words in input contain only lowercase English letters and their lengths don’t exceed 20 characters. In all relations and in all questions the two words are different.

Output
First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print “NO” (without quotes) and ignore it, otherwise print “YES” (without quotes).

After that print q lines, one per each question. If the two words have the same meaning, output 1. If they are opposites, output 2. If there is no relation between them, output 3.

See the samples for better understanding.

Examples
input
3 3 4
hate love like
1 love like
2 love hate
1 hate like
love like
love hate
like hate
hate like
output
YES
YES
NO
1
2
2
2
input
8 6 5
hi welcome hello ihateyou goaway dog cat rat
1 hi welcome
1 ihateyou goaway
2 hello ihateyou
2 hi goaway
2 hi hello
1 hi hello
dog cat
dog hi
hi hello
ihateyou goaway
welcome ihateyou
output
YES
YES
YES
YES
NO
YES
3
3
1
1
2

题意:
给你n个单词,m个关系(两个单词是反义词还是同义词);
然后问你所给的关系里面有没有错的(就是互相抵触了);
最后再给你q个询问,问你两个单词之间的关系是什么;
同义词输出1,反义词输出2,不确定输出3;

带权并查集:不懂的可以看下这道:http://blog.csdn.net/littlewhite520/article/details/53521037
只有两个值 1和 2 两种状态所以%2就行,保持在 0 1,要输出不确定的为3,记住,不在一棵树里面的就是不确定的。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int f[maxn];
int relation[maxn];
map <string,int > mp;
int find(int x)
{
    if(x!=f[x])
    {
        int t=f[x];
        f[x]=find(f[x]);
        relation[x]=(relation[x]+relation[t])%2;
    }
    return f[x];
}
int main()
{
    int n,m,q;
    while(cin>>n>>m>>q)
    {
        string s;
        for(int i=0;i<n;i++)
        {
            cin>>s;
            mp[s]=i;
        }
        for(int i=0;i<n;i++)
        {
            f[i]=i;
            relation[i]=0;
        }
        string s1;
        int v;
        while(m--)
        {
            cin>>v>>s>>s1;
            v--;
            int f1=mp[s];
            int f2=mp[s1];
            int t1=find(f1);
            int t2=find(f2);
            if(t1!=t2)
            {
                printf("YES\n");
                f[t1]=t2;
                relation[t1]=(v-relation[f1]+relation[f2]);
            }
            else
            {
                int p=(relation[f1]-relation[f2]+2)%2;
                if(p==v) puts("YES");
                else
                    puts("NO");
            }
            }
         while(q--)
         {
            cin>>s>>s1;
            int f1=mp[s];
            int f2=mp[s1];
            int t1=find(f1);
            int t2=find(f2);
            if(t1!=t2)
            {
                puts("3");
            }
            else
            {
                int p=(relation[f1]-relation[f2]+2)%2;
                printf("%d\n",p+1 );
            }
         }
    }
}
sas协议(SAS PL-3)之Zoning功能 1 Zoning overview SAS zoning is implemented by a set of zoning expander devices with zoning enabled that define a zoned portion of a service delivery subsystem (ZPSDS)服务子系统. The zoning expander devices control whether a phy is permitted to participate in 阅读详情

相关推荐

Zynq 双核AMP 通信

4、配置离线编译(这里不讲),配置linux的内核地址空间(0x4000_0000改为0x2000_0000),以及单核启动。CPU1设置为0x2000_0000~0x3FFF_FFFF(也可以小于0x3FFF_FFFF)如果禁用CPU1的L2 cache,在CPU1的bsp里面添加编译时候所需要的宏。3、配置工程,将vivado产生的.xsa文件复制到amp_com项目目录下。9、使用petalinux-package --boot 打包。一、vivado工程。5、编译u-boot。

y183128184的博客 1093

Codeforces Round 123 (Div. 2) E. Building Forest(带权并查集)

这个并查集维护的是点的连通性,以及集合中任意两点之间的距离(注意,这个"距离"并不一定代表着原图两点的距离,根据合并情况的不同,代表的信息会是不一样的),并查集能做到的带权并查集也能做到,带权并查集事实上就是并查集的另一扩展。(首先强调,这里的边并不一定代表着单向边,笔者为了方便标记,图中的这些单向边的意义是指出表示一个点的根节点,而在带权并查集中这些单向边应该是双向边)带权并查集事实上是将一些要维护的信息作为"边权",这些信息构成的内容变成"距离",然后经过合并集合后我们就可以高效的查询集合内的信息了。

田所浩二的博客 266

告别ROS1思维:在ROS2 Humble上,用Python搞定MoveIt2机械臂控制的完整流程

本文详细介绍了在ROS2 Humble环境下使用Python控制MoveIt2机械臂的完整流程。从环境配置、架构变革到实战操作,涵盖URDF适配、Action接口编程及性能优化技巧,帮助开发者高效迁移ROS1项目至ROS2平台,实现工业级机械臂控制。

weixin_30352645的博客 453

Codeforces Round #836 (Div. 2) E.Tick, Tock(在线:带权并查集/离线:dfs判环)

Codeforces Round #836 (Div. 2) E.Tick, Tock(在线:带权并查集/离线:dfs判环+计数)

小衣同学的博客 573

Ubuntu下全面解析硬盘健康:从基础检测到性能优化

本文详细介绍了在Ubuntu系统中如何全面监测硬盘健康状态。从安装smartmontools工具、解读SMART关键属性(如重新分配扇区计数、通电时间),到进行性能基准测试(使用dd和fio),最后根据检测结果提供针对性的优化与预警方案,帮助用户有效预防数据丢失并提升硬盘可靠性。

weixin_29223603的博客 290

Ren’py教程《从入门到精通》

Ren’py是什么?Ren'py是一款用于制作视觉小说、冒险游戏、galgame的游戏制作工具,被来自世界各地的数千名创作者使用。Ren'py的名字由Ren’ai和Python混合而成,而Python也是Ren'py所使用的环境语言。Ren'py可以帮助你使用文字、图像和声音来讲述在计算机和移动设备上运行的交互式故事。这些既可以是视觉小说,也可以是生活模拟游戏。易于学习的脚本语言允许 任何人都可以有效地编写大型视觉小说,而它的Python 脚本足以应对复杂的 模拟游戏。

2302_77140651的博客 1万+

并查集

一,并查集 并查集是一种森林,而且是反向森林,即每个节点都指向自己的父亲节点。 根据森林中根节点的个数,所有的节点都分成了若干个不相交的集合。 并查集的主要操作:查找一个节点的祖先、合并两颗树 二,查找祖先 1,普通查找 int find(int x) //找祖先 { int r = x; while (fa[r] != r)r = fa[r]; return r; } 普通查找比较慢,但是有些问题只能用普通查找,不能做路径压缩。 2,带路径压缩的查找 int f....

nameofcsdn的博客 2090

【VoxCPM2】在Windows上从零搭建VoxCPM2 语音生成和语音克隆AI算法

建议你了解清楚VoxCPM2,再来考虑是否需要自己在本地搭建。

AnChenliang_1002的博客 764

codeforces 722C(带权并查集+反向思维)

题意描述 You are given an array consisting of n non-negative integers a 1, a 2, …, a n. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array are destroye

Dejavu的博客 411

am62x A53与R5F通信

AM62x是Ti的一款异构多核芯片。remoteproc驱动,硬编码(写死)了R5F/M4F固件的名字,这样驱动启动时,就会找硬件编码的固件,下面是其对应关系。值得注意的是,linux内核中的M4F remoteproc驱动启动M4F,而linux内核中的R5F remoreteproc驱动不启动R5F,相反,它attach到已经在boot阶段启动的R5F固件上。在/lib/firmware的真实固件名:,而我们生成的固件名如下所示,没有直接对应的,经确认,.out文件就是我们需要的,重命名后即可。

鹰之翔 1365

CREO图文教程:三维设计案例之矿泉水瓶实例图文教程之详细攻略

草绘,先绘制中心线,绘制底部宽度;对称标注:点击左端点,中心线,左端点,中键即可标注;给定高度;样条曲线绘制外形(双击样条曲线,点击下栏的控制模式(第一个按钮),再拉动控制样条曲线上的各个点)打勾即可得到三维实体。......

走向CTO之路 1940

Codeforces 1290 C Prefix Enlightenment —— 带权并查集,有丶东西

This way 题意: 给你一个长度为n的01串,m个几何,每个集合包含1-n的一些数,并且 对于第i个集合,如果你选择了它,那么01串中对应的集合里面的位置的数就会取反。 问你到第i个位置时,前面i个位置都是1,后面的位置随意,问你最少需要选择多少个集合。 题解: 我猜到是并查集,但是只能想到对于第i个集合有取和不取两种情况,之后对于权值怎么考虑就不会了。 有点难讲,主要还是靠自己意会。首先...

天翼之城的博客 361

SAP Word 模板与 ABAP XML 数据流合并机制深度解析

Office Open XML 标准把一个.docx拆分成多个部件(document.xml、customXml\item1.xml 等),天然支持命名空间与 XPath;Word 在渲染时,会扫描<w:sdt>(结构化文档标签)与来确定绑定关系;在 ABAP 端,通过简单字符串替换与 XSLT 变换即可完成数据灌入,无需 COM Automation,安全且易于调试。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 376

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

D. Mahmoud and a Dictionary 链接: http://codeforces.com/contest/766/problem/D 代码: 1 #include&lt;cstdio&gt; 2 #include&lt;cstring&gt; 3 #include&lt;cstdlib&gt; 4 #include&lt;cmath&gt; ...

花海 123

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary

扩展域并查集

我们仍未知道那天所看见的花的名字。 224

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Codeforces Round #396 (Div. 2)D. Mahmoud and a Dictionary(带权并查集)

题目链接:点击打开链接 思路: 带权并查集水题。  带权并查集可以知道在一个集合里的两点间距离。那么这种同义反义关心恰好对应距离的奇偶。 附上一图: 这就是合并的过程。 细节参见代码: #include #include #include #include #include #include #include #include #include #includ

AC_Arthur的专栏 567

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Codeforces Round #396 (Div. 2)D. Mahmoud and a Dictionary【带权并查集】

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new dictionary t

mengxiang000000 592

Codeforces Round #396 (Div. 2) D.Mahmoud and a Dictionary

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new dictionary...

weixin_30920091的博客 95

Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(并查集)

原题链接 D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wan

L. 499

Codeforces #396 (Div. 2) D. Mahmoud and a Dictionary (并查集+map

DescriptionMahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. t

Yishui_lovely 541

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(带权并查集)

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di

CillyB的博客 453

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary (并查集)

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di

LzyRapX 546

Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(关系并查集)

题目链接 题目大意: n个单词,m个关系,q次查询 有两种关系: 1 a b表示a,b两个单词同义 2 a b表示a,b两个单词反义 如果关系跟之前的关系冲突则无视当前关系 每次查询问两个单词属于1还是2,都不属于则输出3一看就发现跟poj1703和poj1182两道关系并查集很像,,可以说是结合后的题。 这里我把关系1,2变成0,1刚好是%2后的数PS:为什

No Program No Life 417

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(并查集)

D. Mahmoud and a Dictionarytime limit per test:4 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard outputMahmoud wants to write a new dictionary that contains n words and re

妍恐龙的博客....^~^眼熟我 376
上一篇: C. Mahmoud and a Message 396 div2 C dp好题
下一篇: 蓝桥 大臣的旅费
黑码
博客等级 码龄10年 76粉丝 454原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值