http://www.lydsy.com/JudgeOnline/problem.php?id=1997

如果两条边在环内相交,那么一定也在环外相交

所以环内相交的两条边,必须一条在环内,一条在环外

这就成了2-sat问题

时间复杂度为(T*(m^2+n)),T 飞

平面图有一个结论:边数<=点数*3-6

m就与n同阶了

判断两条边是否在环内相交:

设一条边为(ui,vi),一条半为(uj,vj)

且 u在环上的编号<v

如果 ui<uj<vi<vj,则两条边会在环内相交

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; #define N 1205
#define M 1440001 int n,m; struct node
{
int u,v;
}e[],g[]; int pos[N]; int tot,front[N],to[M],nxt[M]; int low[N],dfn[N];
int st[N],top; int id[N],cnt; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool init()
{
read(n); read(m);
for(int i=;i<=m;++i) read(e[i].u),read(e[i].v);
int x;
for(int i=;i<=n;++i)
{
read(x);
pos[x]=i;
}
return m<=*n-;
} void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
} void build()
{
int mm=;
int u,v;
for(int i=;i<=m;++i)
{
u=e[i].u; v=e[i].v;
if(pos[u]>pos[v]) swap(u,v);
if(pos[v]==pos[u]+) continue;
if(pos[v]==n && pos[u]==) continue;
g[++mm].u=u; g[mm].v=v;
}
m=mm;
for(int i=;i<=m;++i)
for(int j=;j<=m;++j)
if(i!=j)
if(pos[g[i].u]<pos[g[j].u] && pos[g[j].u]<pos[g[i].v] && pos[g[i].v]<pos[g[j].v])
add(i<<,j<<|),add(j<<,i<<|);
} void tarjan(int x)
{
dfn[x]=low[x]=++tot;
st[++top]=x;
for(int i=front[x];i;i=nxt[i])
if(!dfn[to[i]])
{
tarjan(to[i]);
low[x]=min(low[x],low[to[i]]);
}
else low[x]=min(low[x],dfn[to[i]]);
if(low[x]==dfn[x])
{
cnt++;
while(st[top]!=x) id[st[top--]]=cnt;
id[x]=cnt;
top--;
}
} void solve()
{
tot=;
for(int i=;i<=m;++i)
{
if(!dfn[i<<]) tarjan(i<<);
if(!dfn[i<<|]) tarjan(i<<|);
}
for(int i=;i<=m;++i)
if(id[i<<]==id[i<<|])
{
puts("NO");
return;
}
puts("YES");
} void clear()
{
tot=cnt=;
memset(front,,sizeof(front));
memset(dfn,,sizeof(dfn));
} int main()
{
int T;
read(T);
while(T--)
{
if(!init())
{
puts("NO");
continue;
}
clear();
build();
solve();
}
}

1997: [Hnoi2010]Planar

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 2445  Solved: 916
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

2
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

NO
YES

bzoj千题计划231:bzoj1997: [Hnoi2010]Planar的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划211:bzoj1996: [Hnoi2010]chorus 合唱队

    http://www.lydsy.com/JudgeOnline/problem.php?id=1996 f[i][j][0/1] 表示已经排出队形中的[i,j],最后一个插入的人在[i,j]的i或j ...

  3. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  4. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  5. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  6. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  7. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  8. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  9. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

随机推荐

  1. 移动端三合一瀑布流插件(原生JS)

    没有前言,先上DEMO(手机上看效果更佳)和 原码. 瀑布流形式的图片布局方式在手机等移动端设备上运用广泛,比较常见的是下面前两种: 一.等宽等高 这种形式实现起来非常容易,这里就不再多说. 二.等宽 ...

  2. Mvc4_mvc4跟mysql语法

    mvc4: 子页面:@section A{} 母页面:@RenderSection("A",false) false:别的页面没有定义为A的Section的话 也没事,layout ...

  3. Unity 3D 简易制作摄像机围绕物体随鼠标旋转效果

    Unity 3D 简易制作摄像机围绕物体随鼠标旋转效果 梗概: 一. 摄像机围绕目标物体旋转, 即摄像机离目标物体有一定的距离且旋转轴心为该物体的位置. 二. 当目标物体被障碍物挡住后, 需要将摄像机 ...

  4. LeetCode 141. Linked List Cycle环形链表 (C++)

    题目: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked ...

  5. 【读书笔记】Linux内核设计与实现(第五章)

    5.1 内核通信 系统调用在用户空间和硬件设备之间添加了一个中间层. 该层主要作用: 1.为用户空间提供了一种硬件的抽象接口. 2.保证了系统的稳定和安全. 3.每个进程都运行在虚拟系统中. 在Lin ...

  6. A01-java学习环境准备

    1, 需要去oracle官网下载,JDK     https://www.oracle.com/technetwork/java/javase/downloads/index.html 点击SE Do ...

  7. beta3

    吴晓晖(组长) 过去两天完成了哪些任务 一些细节的debug,部分优化,算法中有关记录的部分 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还剩下哪些任务 组员:刘帅珍 过去两天完成 ...

  8. 查看django版本的方法

    在cmd输入: python -m django --version django-admin --version

  9. [转帖]Windows 使用netsh 命令行方式处理 windows防火墙的方法

    Windows防火墙命令行手册 https://blog.csdn.net/mystudyblog0507/article/details/79617629 简介 netsh advfirewall ...

  10. dos批量导入不受信任的证书及软件限制策略的应用

    certmgr.exe -add "证书.cer" -s -r localMachine Disallowed 导入授信机构 certmgr -add "证书.cer&q ...