当前位置: 首页 > news >正文

BZOJ 4195: [Noi2015]程序自动分析 [并查集 离散化 | 种类并查集WA]

题意:

给出若干相等和不等关系,判断是否可行


woc NOI考这么傻逼的题飞快打了一个种类并查集交上了然后爆零...

发现相等和不等看错了异或一下再叫woc90分

然后发现md$a \neq b, a \neq c,不能得到b = c$

老老实实的把所有相等关系加并查集然后不等关系来判断吧,唉

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=2e6+5;
typedef long long ll;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int n, mp[N], m;
struct meow{
    int x, y, e;
    bool operator <(const meow &a) const {return e<a.e;}
} a[N];
int fa[N], val[N];
int find(int x) {return x==fa[x] ? x : fa[x]=find(fa[x]);}

int main() {
    freopen("in","r",stdin);
    int T=read();
    while(T--) {
        n=read(); m=0;
        for(int i=1; i<=n; i++) 
            mp[++m]=a[i].x=read(), mp[++m]=a[i].y=read(), a[i].e=read()^1;
        sort(mp+1, mp+1+m); m = unique(mp+1, mp+1+m) - mp - 1;
        for(int i=1; i<=m; i++) fa[i]=i, val[i]=0;
        int flag=1, i;
        sort(a+1, a+1+n);
        for(i=1; i<=n && !a[i].e; i++) { 
            a[i].x = lower_bound(mp+1, mp+1+m, a[i].x) - mp;
            a[i].y = lower_bound(mp+1, mp+1+m, a[i].y) - mp;
            fa[find(a[i].x)] = find(a[i].y);
        }
        for(; i<=n; i++) {
            a[i].x = lower_bound(mp+1, mp+1+m, a[i].x) - mp;
            a[i].y = lower_bound(mp+1, mp+1+m, a[i].y) - mp;
            if(find(a[i].x) == find(a[i].y) ) {puts("NO"); flag=0; break;}
        }
        if(flag) puts("YES");
    }
}

 

相关文章:

  • UIButton的titleLabel不同状态字体判断
  • STM32 Flash Download failed
  • H5+css从入门到精通
  • xpath与css的区别
  • PHP类与对象
  • malloc函数及用法
  • SQL基础操作指令
  • IP首部格式[转载]
  • Cisco配置VLAN+DHCP中继代理+NAT转发上网
  • 让angular-cli工程基于ExpressJS服务,为对接后台API做准备
  • 面空间数据中网格索引和四叉树索引的结合及优化的一种方案
  • Python学习(20):Python函数(4):关于函数式编程的内建函数
  • socket.io中文文档
  • Digester 的使用(tomcat中server.xml and web.xml 的加载)
  • 我的MYSQL学习心得(九) 索引
  • linux安装openssl、swoole等扩展的具体步骤
  • node学习系列之简单文件上传
  • PaddlePaddle-GitHub的正确打开姿势
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • PHP 小技巧
  • React Native移动开发实战-3-实现页面间的数据传递
  • Spring Cloud(3) - 服务治理: Spring Cloud Eureka
  • Sublime text 3 3103 注册码
  • Traffic-Sign Detection and Classification in the Wild 论文笔记
  • XML已死 ?
  • 解析 Webpack中import、require、按需加载的执行过程
  • 前言-如何学习区块链
  • 深入浅出Node.js
  • 微信开源mars源码分析1—上层samples分析
  • ###C语言程序设计-----C语言学习(3)#
  • #我与Java虚拟机的故事#连载18:JAVA成长之路
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (70min)字节暑假实习二面(已挂)
  • (function(){})()的分步解析
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (带教程)商业版SEO关键词按天计费系统:关键词排名优化、代理服务、手机自适应及搭建教程
  • (转)EXC_BREAKPOINT僵尸错误
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • ***详解账号泄露:全球约1亿用户已泄露
  • ./和../以及/和~之间的区别
  • .NET DataGridView数据绑定说明
  • .Net MVC4 上传大文件,并保存表单
  • .NET 实现 NTFS 文件系统的硬链接 mklink /J(Junction)
  • .net连接MySQL的方法
  • .NET下ASPX编程的几个小问题
  • .net项目IIS、VS 附加进程调试
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • .stream().map与.stream().flatMap的使用
  • /dev/VolGroup00/LogVol00:unexpected inconsistency;run fsck manually
  • @Bean, @Component, @Configuration简析
  • @CacheInvalidate(name = “xxx“, key = “#results.![a+b]“,multi = true)是什么意思
  • @ConfigurationProperties注解对数据的自动封装
  • [120_移动开发Android]008_android开发之Pull操作xml文件
  • [Flutter]WindowsPlatform上运行遇到的问题总结
  • [Gamma]阶段测试报告