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. 网上的证明( ...
随机推荐
- wpf 快速建立可以拖动对象
1.引用两个.net 程序集 2.xaml name space导入 xmlns:i ="http://schemas.microsoft.com/expression/2010/inter ...
- List遍历删除 或取指定的前N项
class Program { static void Main(string[] args) { /* * List遍历删除 或取指定的前N项 */ List<PerSon> listP ...
- Win10《芒果TV》商店版更新v3.2.4:新增跨年事件直播、电视台直播,新年快乐
听说半个娱乐圈都来了,<芒果TV>UWP版邀您一起,于2016年12月31日晚,观看<湖南卫视2016·2017跨年演唱会>直播,请更新v3.2.4版,主要新增大事件直播和电视 ...
- 微信小程序把玩(二十八)image组件
原文:微信小程序把玩(二十八)image组件 image组件也是一个程序不可缺少的,可以这样说一个app中image组件随处可以看到,一般 image有两种加载方式第一种是网络图片第二种是本地图片资源 ...
- Docker Explanation and Apache Image
https://blog.sajjan.com.np/2017/02/05/docker-getting-started-containers-ubuntu/ https://blog.sajjan. ...
- Maven 安装和使用
Maven 安装和使用 1.下载 http://maven.apache.org/download.cgi 2.tar -bin.tar.gz 3.环境变量 /etc/profile export M ...
- linux oracle 启动全过程
一:启动oracle [root@ccoracle ~]# su -l oracle [oracle@ccoracle ~]$ sqlplus /nolog SQL*Plus: Release 10. ...
- spring boot之security
上一节的时候,我们打开了springboot的端点,有一些数据是非常敏感的,比如/shutdown. 这一节,我们要给一些敏感信息加上权限控制. spring boot本身的security模块就很好 ...
- MSVBVM60.dll中函数
本文转载!!! 原文作者:飘云(飘云阁安全论坛) 原文地址:http://www.chinapyg.com/forum.php?mod=viewthread&tid=2225&high ...
- spring 5.x 系列第15篇 —— 整合dubbo (xml配置方式)
文章目录 一. 项目结构说明 二.项目依赖 三.公共模块(dubbo-common) 四. 服务提供者(dubbo-provider) 4.1 productService是服务的提供者( 商品数据用 ...