连边的点用并查集检查是否有环,如果他们的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. 关于XXE

    NJUPT CTF2019: 做题的时候,抓包看了一下,响应XML格式消息,并没有严格过滤,这道题读文件, <!DOCTYPE foo [ <!ENTITY xxe SYSTEM &quo ...

  2. Python Turtle模块的简单应用

    时钟 import turtle as t import datetime as dt #画出背景 game = t.Screen() game.bgcolor("white") ...

  3. 傻傻分不清之 Cookie、Session、Token、JWT

    傻傻分不清之 Cookie.Session.Token.JWT 什么是认证(Authentication) 通俗地讲就是验证当前用户的身份,证明“你是你自己”(比如:你每天上下班打卡,都需要通过指纹打 ...

  4. Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  5. ansible笔记(12):变量(一)

    1.定义变量规范 先说说怎样定义变量,变量名应该由字母.数字.下划线组成,变量名需要以字母开头,ansible内置的关键字不能作为变量名. 2.定义变量,使用关键字:vars 定义变量用vars,调用 ...

  6. 【Python】输入身份证号,输出出生日期

    name = input("请输入你的名字:") id = input("请输入你的身份证号码:") year = id[6:10] month = id[10 ...

  7. js json -> <-object

    1.利用原生JSON对象,将对象转为字符串 var jsObj = {}; jsObj.testArray = [1,2,3,4,5]; jsObj.name = 'CSS3'; jsObj.date ...

  8. jqGrid colModel 参数(来自中文手册)

    jqGrid colModel 参数 ColModel 是jqGrid里最重要的一个属性,设置表格列的属性. 属性 数据类型 备注 默认值 align string left, center, rig ...

  9. python3练习100题——021

    题目很容易,只要理清了数学思想就可以解出来,所以本来不是很喜欢这种题. 后来看到有大神用递归解,觉得还是很值得学习的. 原题链接:http://www.runoob.com/python/python ...

  10. LOJ 劳孙肉饼

    题目链接 XRRRRQAQ 去学文化的的样子太萌啦!!! XRRRRQAQ 在课上太无聊,以至于吃起了劳孙(你不用知道这是什么) 显然劳孙是一个 N * M 的肉饼(即N行 M 列) XRRRRQAQ ...