bzoj千题计划231:bzoj1997: [Hnoi2010]Planar
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
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
bzoj千题计划231:bzoj1997: [Hnoi2010]Planar的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- 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 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
随机推荐
- 部署jar项目常用命令
netstat -tunlp | grep ×× 查询出端口为××在运行应用的线程ip kill -9 ×× 关闭线程ip 为 ××的应用 rm -f ××.jar ...
- PHP学习 流程控制和数组
flow control 流程控制decision structure 判断结构loop structure 循环结构 if(condition){statement1;} if(){}else{} ...
- maybe i have no answer
怎么说呢,我从小学开始到高中,大学.我觉得老师对大家都是一样的,虽然我因为父母的原因可能和老师接触比较多,但是学业上其实没什么帮助的. 我更希望老师能给我人生道路上的指点,虽然自己的道路确实是自己走出 ...
- JavaMail实现邮箱之间发送邮件功能
package com.minstone.message.util; import java.util.Date; import java.util.Properties; import javax. ...
- Beta 冲刺 三
团队成员 051601135 岳冠宇 031602629 刘意晗 031602248 郑智文 031602330 苏芳锃 031602234 王淇 照片 项目进展 岳冠宇 ## 项目进展 昨天的困难 ...
- Final发布点评
1. 约跑App——nice!:为改进演示效果,本组使用摄像头实时采集投影的方式展示其作品,是一种演示的创新.本组重点放在了修改上次来着其他组发现的bug,不过新功能上好像没有加入多少,可能是保证软 ...
- Oracle client 使用 .net程序连接 数据库时 出现 8.1.7 的解决办法
1. GS产品 连接oracle数据库时出现错误图示 2. 其实解决这个问题的办法很简单 一般是 修改一下 Oracle的app 目录的权限 最简单的办法是增加 everyone 权限 然后重启机器即 ...
- Python的文件读写
目录 读文件 操作文件 读取内容 面试题的例子 写文件 操作模式 指针操作 字符编码 读文件 操作文件 打开一个文件用open()方法(open()返回一个文件对象,它是可迭代的): 文件使用完毕后必 ...
- SpringBoot(十四)_springboot使用内置定时任务Scheduled的使用(一)
为什么使用定时? 日常工作中,经常会用到定时任务,比如各种统计,并不要求实时性.此时可以通过提前设置定时任务先把数据跑出来,后续处理起来更方便. 本篇文章主要介绍 springboot内置定时任务. ...
- selectTree & bug
selectTree & bug 相对路径 & 绝对路径 http://192.168.58.189:8080/hui/#/components/selectTree https:// ...