博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[bzoj4195][Noi2015]程序自动分析
阅读量:6882 次
发布时间:2019-06-27

本文共 1048 字,大约阅读时间需要 3 分钟。

题目大意:有$n(n\leqslant10^6)$个变量,有若干限制,形如$x_l$与$x_r$必须相等或不相等,问是否有解

题解:并查集,把相同的塞在一个集合里,最后判一下不相等的是否在一个集合内,是则无解

卡点:当成了元素非$0$即$1$

 

C++ Code:

#include 
#include
#define maxn 1000010int Tim, n, tot;int v[maxn << 1], f[maxn], l[maxn], r[maxn], e[maxn];int find(int x) { return x == f[x] ? x : (f[x] = find(f[x])); }inline void merge(int a, int b) { f[find(a)] = find(b); }int main() { scanf("%d", &Tim); while (Tim --> 0) { scanf("%d", &n); tot = 0; for (int i = 0; i < n; ++i) { scanf("%d%d%d", l + i, r + i, e + i); v[tot++] = l[i], v[tot++] = r[i]; } tot = (std::sort(v, v + tot), std::unique(v, v + tot) - v); for (int i = 0; i < tot; ++i) f[i] = i; for (int i = 0; i < n; ++i) { l[i] = std::lower_bound(v, v + tot, l[i]) - v; r[i] = std::lower_bound(v, v + tot, r[i]) - v; if (e[i]) merge(l[i], r[i]); } bool check = true; for (int i = 0; i < n; ++i) if (!e[i]) check &= find(l[i]) != find(r[i]); puts(check ? "YES" : "NO"); } return 0;}

  

转载于:https://www.cnblogs.com/Memory-of-winter/p/10363225.html

你可能感兴趣的文章
Eclipse ME 安装详解(Windows XP)
查看>>
IE8及以下不支持trim()的处理方法
查看>>
centos反编译APK包
查看>>
python 位操作符 左移和右移 运算
查看>>
预备作业①
查看>>
跨域 - jsonp轻松搞定跨域请求
查看>>
css布局 - 工作中常见的两栏布局案例及分析
查看>>
个人代码库のC#背景色渐变的功能
查看>>
基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境
查看>>
承接上面一遍的(后续步骤)
查看>>
杂笔感想
查看>>
Source Insight 常用设置
查看>>
android anr什么意思?
查看>>
视频: DroidPilot - 增强多应用集成测试 - V2.1.0 (新)
查看>>
python实现逐行替换超大文件中的字符串
查看>>
软件工程例子
查看>>
python全栈开发,Day43(引子,协程介绍,Greenlet模块,Gevent模块,Gevent之同步与异步)...
查看>>
异步编程与多线程编程的联系和区别
查看>>
单例模式(Singleton Pattern)
查看>>
SQL Server
查看>>