Bzoj 1997 [Hnoi2010]Planar题解
1997: [Hnoi2010]Planar
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 2224 Solved: 824
[Submit][Status][Discuss]
Description

Input

Output

Sample Input
6 9
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6
1 4 2 5 3 6
5 5
1 2
2 3
3 4
4 5
5 1
1 2 3 4 5
Sample Output
YES
HINT
Source
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#define N 300
using namespace std;
struct ro{
int to;
int next;
}road[**];
int t,n,m,zz,a[],f[][],pos[N],zz1;
void build(int x,int y)
{
zz++;
road[zz].to=y;
road[zz].next=a[x];
a[x]=zz;
}
int dfn[],low[],zz2,top,st[],bel[],zz3;
bool rd[],rd2[];
void tar(int x)
{
zz2++;
dfn[x]=low[x]=zz2;
top++;
st[top]=x;
rd[x]=rd2[x]=;
for(int i=a[x];i>;i=road[i].next)
{
int y=road[i].to;
if(!rd2[y])
{
tar(y);
low[x]=min(low[x],low[y]);
}
else if(rd[y])
{
low[x]=min(dfn[y],low[x]);
}
}
if(dfn[x]==low[x])
{
zz3++;
int v;
do{
v=st[top];
top--;
rd[v]=;
bel[v]=zz3;
}while(dfn[v]!=low[v]);
}
}
int main(){
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
top=;
memset(rd2,,sizeof(rd2));
zz3=zz2=;
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
zz=zz1=;
memset(bel,,sizeof(bel));
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&f[i][],&f[i][]);
}
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
pos[x]=i;
}
if(n*-<m)
{
printf("NO\n");
continue;
}
for(int i=;i<=m;i++)
{
int fr=f[i][],to=f[i][];
fr=pos[fr],to=pos[to];
if(fr>to)swap(fr,to);
if(to-fr==||(to==n&&fr==))continue;
zz1++;
f[zz1][]=fr,f[zz1][]=to;
}
m=zz1;
for(int i=;i<=m;i++)
{
for(int j=i+;j<=m;j++)
{
if(f[i][]<f[j][]&&f[i][]<f[j][]&&f[i][]>f[j][])
{
build(i*,j*-);
build(j*-,i*);
build(j*,i*-);
build(i*-,j*);
}
else if(f[j][]<f[i][]&&f[j][]<f[i][]&&f[i][]<f[j][])
{
build(i*,j*-);
build(j*-,i*);
build(j*,i*-);
build(i*-,j*);
}
}
}
for(int i=;i<=*m;i++)
{
if(!rd2[i])
{
tar(i);
}
}
bool yx=;
for(int i=;i<=m;i++)
{
if(bel[i*]==bel[i*-])
{
yx=;
break;
}
}
if(yx)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return ;
}
Bzoj 1997 [Hnoi2010]Planar题解的更多相关文章
- BZOJ 1997: [Hnoi2010]Planar( 2sat )
平面图中E ≤ V*2-6.. 一个圈上2个点的边可以是在外或者内, 经典的2sat问题.. ----------------------------------------------------- ...
- [BZOJ 1997][HNOI2010]Planar(2-SAT)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1997 分析: 考虑每条边是在圈子里面还是圈子外面 所以就变成了2-SAT判定问题了= ...
- bzoj 1997 [Hnoi2010]Planar——2-SAT+平面图的一个定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1997 平面图的一个定理:若边数大于(3*点数-6),则该图不是平面图. 然后就可以2-SAT ...
- bzoj 1997: [Hnoi2010]Planar
#include<cstdio> #include<cstring> #include<iostream> #define M 20005 #define N 20 ...
- bzoj 1997: [Hnoi2010]Planar【瞎搞+黑白染色】
脑补一下给出的图:一个环,然后有若干连接环点的边,我们就是要求这些边不重叠 考虑一下不重叠的情况,两个有交边一定要一个在环内一个在环外,所以把相交的边连边,然后跑黑白染色看是否能不矛盾即可(可能算个2 ...
- 1997: [Hnoi2010]Planar
1997: [Hnoi2010]Planar 链接 分析: 首先在给定的那个环上考虑进行操作,如果环内有有两条边相交,那么可以把其中的一条放到环的外面去.所以转换为2-sat问题. 像这样,由于1-4 ...
- BZOJ1997:[HNOI2010]PLANAR——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=1997 https://www.luogu.org/problemnew/show/P3209 若能 ...
- bzoj千题计划231:bzoj1997: [Hnoi2010]Planar
http://www.lydsy.com/JudgeOnline/problem.php?id=1997 如果两条边在环内相交,那么一定也在环外相交 所以环内相交的两条边,必须一条在环内,一条在环外 ...
- [bzoj1997][Hnoi2010]Planar(2-sat||括号序列)
开始填连通分量的大坑了= = 然后平面图有个性质m<=3*n-6..... 由平面图的欧拉定理n-m+r=2(r为平面图的面的个数),在极大平面图的情况可以代入得到m=3*n-6. 网上的证明( ...
随机推荐
- SQL Server 游标运用:查看一个数据库所有表大小信息(Sizes of All Tables in a Database)
原文:SQL Server 游标运用:查看一个数据库所有表大小信息(Sizes of All Tables in a Database) 一.本文所涉及的内容(Contents) 本文所涉及的内容(C ...
- EasyUI 实现编辑功能,给Combobox 赋值
1: <input id="RequestType" name="RequestType" class="easyui-combobox&quo ...
- MiTeC System Information Component Suite 10.9.2 D5-XE3 Full Source
The most complex system information probe in Delphi world, it consists of many standalone components ...
- stdlib.h,string.h,wchar.h的函数列表(cplusplus.com就有,很清楚)goodx
Multibyte characters mblen Get length of multibyte character (function ) mbtowc Convert multibyte se ...
- 12 寸 Retina MacBook 的大秘密: 可用移动电源充电
苹果新款12寸Retina MacBook虽然只有一个USB-C接口,但这个接口的能力却十分强大.它不仅可以进行数据传输和视频输出,还能接收和输入电源.这也就是说,你可以使用移动电源对其进行充电,如果 ...
- 开启Qt Lite Project
发布: http://blog.qt.io/blog/2017/01/23/qt-5-8-released/ 说法一:Qt Lite” is not a tool, but a concept tha ...
- window8 飘带与页面切换效果
演示效果如下 用鼠标点击滑动试试就能看到效果了 ^_^ iscroll 不仅可以做到自然滚动条的效果,看官方文档还可以用来做页面切换的效果,很好很强大. 所以我结合流行的飘带元素做了个简单的例子.. ...
- FMX有两种消息处理的实现方式,一种是用TMessageManager来实现自定义的消息,另外一种象TEdit中的实现,直接声明消息方法(firemonkey messaging)
看FMX代码,发现有两种消息处理的实现方式,一种是用TMessageManager来实现自定义的消息,另外一种象TEdit中的实现,直接声明消息方法. 早前,看过文章说TMessageManage ...
- Elasticsearch ML
Elastic公司在收购了Prelert半年之后,终于在Elasticsearch 5中推出了Machine Learning功能.Prelert本身就擅长做时序性数据的异常检测,从这点上讲也比较契合 ...
- Qt5 中对 C++11 一些新特性的封装
在 Qt5 中,提供更多 C++11 的特性支持,接下来我们将进行详细的说明. slots (槽) 的 Lambda 表达式 Lambda表达式 是 C++11 中的一个新语法,允许定义匿名函数.匿名 ...