当前位置:网站首页>Food chain (day 79)
Food chain (day 79)
2022-07-27 03:40:00 【Zhangxueheng】
List of articles
1: subject
There are three kinds of animals in the animal kingdom A,B,C, The food chain of these three kinds of animals forms an interesting ring .
A eat B,B eat C,C eat A.
existing N Animals , With 1∼N Number .
Every animal is A,B,C One of the , But we don't know which one it is .
There are two ways of saying it N Describe the food chain of animals :
The first is 1 X Y, Express X and Y It's the same kind .
The second is 2 X Y, Express X eat Y.
This man is right N Animals , Use the two statements above , Say... Sentence by sentence K Sentence , this K Some sentences are true , Some are fake .
When a sentence satisfies one of the following three , This is a lie , Otherwise, it's the truth .
The current words conflict with some of the real words in front , It's a lie ;
In the current conversation X or Y Than N Big , It's a lie ;
The current words mean X eat X, It's a lie .
Your task is based on the given N and K Sentence , The total number of output lies .
Input format
The first line is two integers N and K, Separated by a space .
following K Each row is three positive integers D,X,Y, Separate the two numbers with a space , among D The type of statement .
if D=1, said X and Y It's the same kind .
if D=2, said X eat Y.
Output format
There's only one whole number , The number of lies .
Data range
1≤N≤50000,
0≤K≤100000
sample input :
100 7
1 101 1
2 1 2
2 2 3
2 3 3
1 1 3
2 3 1
1 5 5
sample output :
3
2: Code implementation
#include<iostream>
using namespace std;
const int N=1000010;
int n,m;
int p[N],d[N];
int find(int x)
{
if(p[x]!=x)
{
int t=find(p[x]);
d[x]+=d[p[x]];
p[x]=t;
}
return p[x];
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)p[i]=i;
int res=0;
while (m -- ){
int t,x,y;
scanf("%d%d%d",&t,&x,&y);
if(x>n || y>n)res++;
else
{
int px=find(x),py=find(y);
if(t==1)
{
if(px==py && (d[x]-d[y])%3)res++;
else if(px!=py)
{
p[px]=py;
d[px]=d[y]-d[x];
}
}
else
{
if(px==py && (d[x]-d[y]-1)%3)res++;
else if(px!=py)
{
p[px]=py;
d[px]=d[y]+1-d[x];
}
}
}
}
printf("%d\n",res);
return 0;
}
边栏推荐
- Introduction to redis
- How to interact with the server when the client sends an SQL message
- Explain详解
- DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
- 基于OpenCV的轮廓检测(2)
- Technology vane | interpretation of cloud native technology architecture maturity model
- [1206. Design skip table]
- Safe-arc/warner power supply maintenance xenon lamp power supply maintenance analysis
- 2022牛客多校第二场的J -- 三分做法
- 常见弱口令大全
猜你喜欢

A new paradigm of distributed deep learning programming: Global tensor

Activiti5.22.0 extension supports domestic databases, taking gbase database as an example
![[tree chain dissection] template question](/img/6b/7ec6f36d5f2373aee163c2cb766b29.png)
[tree chain dissection] template question

代码审查金字塔

mysql如何优化

The diagram of user login verification process is well written!

复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别

Practice of online problem feedback module (XV): realize the function of online updating feedback status

Message rejected MQ

Quick sequencing and optimization
随机推荐
spark学习笔记(四)——sparkcore核心编程-RDD
技术风向标 | 云原生技术架构成熟度模型解读
Deep learning vocabulary embedded, beam search
Quick sequencing and optimization
Graphic SQL, this is too vivid!
The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
The application and significance of digital twins are the main role and conceptual value of electric power.
[understanding of opportunity -52]: the depth of communication varies from person to person
A new paradigm of distributed deep learning programming: Global tensor
《稻盛和夫给年轻人的忠告》阅读笔记
Introduction to database - Introduction to database
It's too strong. An annotation handles the data desensitization returned by the interface
榕树贷款,
Insert pictures and videos in typera
Comprehensive care analysis lyriq Ruige battery safety design
Deployment of ruoyi's environment and operation of the system
客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实
Mysql: summary of common sub database and sub table schemes of Internet companies
Csu18m91 is used as the master controller of the intelligent scale scheme
Redis source code learning (33), command execution process