程序自动化分析 求调
  • 板块学术版
  • 楼主LOVELL
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/10/21 10:27
  • 上次更新2023/11/2 12:18:38
查看原帖
程序自动化分析 求调
334292
LOVELL楼主2023/10/21 10:27

题目链接

 
#include <bits/stdc++.h>
using namespace std;
int t;
const int N=2e6+10;
int fa[N];
int n;
int find(int x){
    if(fa[x]==x)return x;
    return fa[x]=find(fa[x]);
}
void me(int x,int y){
    int x1=find(x),y1=find(y);
    if(x1==y1)return ;
    fa[x1]=y1;
}
struct node{
    int u,v,d;
};
int cnt=0;
unordered_map <int,int> s;
int get(int x){
    if(s.count(x)==0)s[x]=++cnt;
    return s[x];
}
bool solve(){
    for(int i=1;i<=n;i++)fa[i]=i;
    cnt=0;
    s.clear();
    node p[N];
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        p[i].u=get(x);
        p[i].v=get(y);
        p[i].d=z;
    }
    
    for(int i=1;i<=n;i++){
        int x=p[i].u;
        int y=p[i].v;
        if(p[i].d==1){
            me(x,y);
        }
    }
    for(int i=1;i<=n;i++){
        int x=p[i].u;
        int y=p[i].v;
        if(p[i].d==0){
            if(find(x)==find(y)){
                return false;
            }
        }
    }
    return true;
}
int main(){
    cin>>t;
    while(t--){
        if(solve()){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

70分,是哪里没考虑到呢

2023/10/21 10:27
加载中...