当前位置:网站首页>[acwing 237. program automatic analysis] parallel search + discretization
[acwing 237. program automatic analysis] parallel search + discretization
2022-06-11 13:34:00 【Yuzhibo one dozen seven~】
The question :
Here you are. n A relationship , Every relationship is made up of x,y,st Composed of , When st = 1 I mean x and y equal , When st = 0 Yes means yes x and y It's not equal , Now give you this n A relationship , Ask if these relationships are contradictory .
analysis :
The equality relation can be regarded as the union of search sets in a set , The unequal relation can be regarded as that the search set is not in a set , Input x and y The upper limit is 1e9, But at most 2e5 Number , Then we can discretize , Because there are no rules on the order , It does not belong to order preserving discretization , So it can be used map To discretize , Here we use unordered_map It will be better than map Much faster , Personal test , Common map Just TLE 了 , But with unordered_map It's over , After discretization, you can make a judgment , We adopt the strategy of looking at equal relations first and then unequal relations , Because this input sequence is actually useless , And there is no error in the equality relation , We can judge the unequal relationship later , See the code below :
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<climits>
#include<unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef unsigned long long ull;
const int mod = 1e9+7;
const int N = 100010;
unordered_map<int,int> mp;
struct node{
int x,y,st;
}g[N];
int pa[N+N];
int find(int x){
if(x != pa[x]) pa[x] = find(pa[x]);
return pa[x];
}
int main(){
int _;
cin>>_;
while(_--){
int n;
mp.clear();
scanf("%d",&n);
int cnt = 0;
for(int i=1;i<=n;i++){
scanf("%d%d%d",&g[i].x,&g[i].y,&g[i].st);
if(!mp[g[i].x]) mp[g[i].x] = ++cnt;
if(!mp[g[i].y]) mp[g[i].y] = ++cnt;
}
for(int i=1;i<=cnt;i++) pa[i] = i;
int flag = 1;
for(int i=1;i<=n;i++){
int x = mp[g[i].x],y = mp[g[i].y];
if(g[i].st == 1){
pa[find(x)] = find(y);
}
}
for(int i=1;i<=n;i++){
int x = mp[g[i].x],y = mp[g[i].y];
if(g[i].st == 0){
if(find(x) == find(y)){
flag = 0;
break;
}
}
}
if(flag) puts("YES");
else puts("NO");
}
return 0;
}
边栏推荐
- 关于分布式锁的续命问题——基于Redis实现的分布式锁
- JSP implementation of performance appraisal system for bank counter business
- [backtrader source code analysis 46] cerebro Py code comments (boring, one of the core backtrader codes, recommended for reading, comments for reference only)
- 无延时/无延迟视频直播实例效果案例
- JSP实现银柜台业务绩效考核系统
- C # set the cursor shape of forms and systems
- Nomad application layout scheme 07 of hashicopy (submit job)
- In 2022, capture these 12 data and analyze trends!
- 中国 SaaS 发展落后美国 10 年,仍需借助创新、开源、并购等策略发力 | ArchSummit
- 优化调度(火电、风、储能)(Matlab实现)
猜你喜欢

No delay / no delay live video instance effect cases

Introduction to reverse learning - excellent assembly debugging tool OllyDbg
Explanation of waitgroup usage in go language learning

【信号去噪】基于稀疏性 (BEADS) 实现色谱基线估计和去噪附matlab代码和论文

高比例风电电力系统储能运行及配置分析(Matlab实现)

Using vscode code code template to improve mobx coding efficiency

RS485(Modbus RTU)工业RFID读写器CK-FR03-A01与PLC三菱FX5U的通讯操作说明

马斯克称自己不喜欢做CEO,更想做技术和设计;吴恩达的《机器学习》课程即将关闭注册|极客头条...

JSP implementation of performance appraisal system for bank counter business

关于uni-app 配置 APP 不显示顶部标题栏设置
随机推荐
Application choreography nomad vs. kubernetes
【Multisim仿真】555闪灯实验
【201】php异常处理-PHP中的try catch finally异常处理
关于分布式锁的续命问题——基于Redis实现的分布式锁
论文导读 | 机器学习在数据库基数估计中的应用
Optimal dispatching (thermal power, wind and energy storage) (realized by Matlab)
Unity detects whether the object is within the viewing cone of the camera
Go 如何减少供应链攻击?
The end of an era! After ten years, Wu Enda's classic machine learning course closed its registration this month and launched a new course
shader着色器
优化调度(火电、风、储能)(Matlab实现)
Ecplise cannot connect to SQL Server
After five years of losing the lawsuit, the trillion reptile army is ready to move
cadence SPB17.4 - group operation(add to group, view group list, delete group)
在启牛开的证券账户安全吗?如何申请低佣金的股票账户?
风电随机性动态经济调度模型(Matlab代码实现)
折叠表达式
六.开发记录之实验室服务器LXD部署
Is the securities account opened in qiniu safe? How to apply for a low commission stock account?
VIM secondary replacement