记录编号 |
585231 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOI 2001]食物链 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.045 s |
提交时间 |
2023-12-01 16:47:04 |
内存使用 |
2.52 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 15e4+10;
int n,m,ans;
int fa[N];
int find(int x){
if(x == fa[x])return x;
return fa[x] = find(fa[x]);
}
void merge(int x,int y){
if(x == y)return;
fa[x] = y;
}
int main(){
freopen("eat.in","r",stdin);
freopen("eat.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1;i <= 3*n;i++)fa[i] = i;//A->B->C->A ->代表吃的关系
for(int i = 1;i <= m;i++){
int op,x,y;scanf("%d%d%d",&op,&x,&y);
if(x > n || y > n){ans++;continue;}
if(op == 1){
if(find(x) == find(y+n) || find(y) == find(x+n))ans++;
else{
merge(find(x),find(y));
merge(find(x+n),find(y+n));
merge(find(x+2*n),find(y+2*n));
}
}
else{
if(find(x) == find(y) || find(y) == find(x+n))ans++;
else{
merge(find(x),find(y+n));
merge(find(x+n),find(y+2*n)) ;
merge(find(x+2*n),find(y));
}
}
}
printf("%d\n",ans);
return 0;
}