连边的点用并查集检查是否有环,如果他们的fa是同一个点说明绕了一圈绕回去了。n个点一共能连n-1条边,如果小于n-1条边说明存在多个联通块。

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[],b[];
int u[];
int v[];
int fa[];
int find_(int x){
if(fa[x]==x)
return x;
return fa[x]=find_(fa[x]);
}
set<int>st;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
fa[i]=i;
for(int i=;i<=n;++i){
cin>>a[i]>>b[i];
u[a[i]]=i;
v[b[i]]=i;
}
int cnt=;
int temp=;
for(int i=;i<=*n;++i){
if(u[i]){
temp=u[i];
for(auto it:st){
if(it>b[u[i]]){
break;
}
else{
int x=find_(v[it]);
int y=find_(temp);
if(x!=y){
++cnt;
fa[x]=y;
}
else{
cout<<"NO\n";
return ;
}
}
}
st.insert(b[u[i]]);
}
else{
temp=v[i];
st.erase(st.find(b[v[i]]));
}
}
if(cnt==n-)
cout<<"YES\n";
else
cout<<"NO\n";
return ;
}

Educational Codeforces Round 78 (Rated for Div. 2)D(并查集+SET)的更多相关文章

  1. Educational Codeforces Round 64 (Rated for Div. 2)D(并查集,图)

    #include<bits/stdc++.h>using namespace std;int f[2][200007],s[2][200007];//并查集,相邻点int find_(in ...

  2. Educational Codeforces Round 78 (Rated for Div. 2) D. Segment Tree

    链接: https://codeforces.com/contest/1278/problem/D 题意: As the name of the task implies, you are asked ...

  3. Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam

    链接: https://codeforces.com/contest/1278/problem/C 题意: Karlsson has recently discovered a huge stock ...

  4. Educational Codeforces Round 78 (Rated for Div. 2) B. A and B

    链接: https://codeforces.com/contest/1278/problem/B 题意: You are given two integers a and b. You can pe ...

  5. Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing

    链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being ...

  6. 【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)

    比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 ...

  7. Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)

    题:https://codeforces.com/contest/1278/problem/B 思路:还是把1~n分配给俩个数,让他们最终相等 假设刚开始两个数字相等,然后一个数字向前走了abs(b- ...

  8. Educational Codeforces Round 78 (Rated for Div. 2)

    A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...

  9. Educational Codeforces Round 78 (Rated for Div. 2) --补题

    链接 直接用数组记录每个字母的个数即可 #include<bits/stdc++.h> using namespace std; int a[26] = {0}; int b[26] = ...

  10. Educational Codeforces Round 78 (Rated for Div. 2) 题解

    Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...

随机推荐

  1. 转载:openmax基本概念

    https://yellowmax.blog.csdn.net/article/details/78080168 https://yellowmax.blog.csdn.net/article/det ...

  2. CLOUD将excel数据引入单据体

    http://club.kingdee.com/forum.php?mod=viewthread&tid=989239 http://club.kingdee.com/forum.php?mo ...

  3. Python 之路Day13

    匿名函数 一行函数 lambda == def -- 关键字 lambda x:x x 是普通函数的形参(位置,关键字……)可以不接收参数,可以不写 :x 是普通函数的函数值(只能返回一个数据类型), ...

  4. [AHOI2002] 芝麻开门 - 数论

    求 \(n^k\) 的因子和, \(n \leq 2^{16}, k \leq 20\) Solution \[\prod_i \frac{p_i^{q_ik+1}-1}{p_i-1}\] #incl ...

  5. BK: How to read a book 第一篇

    第一章 阅读的活力与艺术 主动阅读 VS 被动阅读(新闻媒体) 作者与读者:投手与捕手的关系. 阅读的目标: 为获得资讯而读,以及为求得理解而读. 为获得咨讯而读,不会增加我们的理解力.比如阅读报纸, ...

  6. Selenium3+python自动化009- 多选框

    多选框 # 随机选择多选框# sports=driver.find_elements_by_name("sport")# maxnum=len(sports)# num=rando ...

  7. 全栈高级web前端工程师的必经之路

    这是最近整理的一个进阶高级web工程师的技术栈 同时也是激励自己每天来看一下离真正的王者还有多少距离! 过段时间再来反思一下自己进步了多少? ------------------------20190 ...

  8. Python RSA

    # -*- coding: utf-8 -*- from Crypto import Random from Crypto.Hash import SHA from Crypto.Cipher imp ...

  9. linux 中对 mysql 数据库的基本命令

    显示数据库列表 show databases; 显示库中的数据表 use mysql: // 打开库 show tables; 建库 create database 库名; 建库是设置好字符编码: c ...

  10. [CF]Round514

    A Cashier 题意:一个人,一天的工作时长为\(L\),从第\(t_i\)时刻开始有长度为\(l_i\)的工作,他想在工作间隙抽烟,抽一根要\(a\)分钟,问能抽几根. 直接模拟. B Forg ...