1997: [Hnoi2010]Planar
1997: [Hnoi2010]Planar
分析:
首先在给定的那个环上考虑进行操作,如果环内有有两条边相交,那么可以把其中的一条放到环的外面去。所以转换为2-sat问题。

像这样,由于1-4和2-3在环内相交了,所以可以把1-4放到环外,就变成了下图。

代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
struct Edge{ int to, nxt; } e[];
int head[N], dfn[N], low[N], bel[N], sk[N], c[N], pos[N], top, Index, tot, En;
bool vis[N];
pair<int,int> g[]; inline void add_edge(int u,int v) {
++En; e[En].to = v, e[En].nxt = head[u]; head[u] = En;
}
void tarjan(int u) {
low[u] = dfn[u] = ++Index;
sk[++top] = u; vis[u] = ;
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
}
if (vis[v]) low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
++tot;
do {
vis[sk[top]] = ;
bel[sk[top]] = tot;
top --;
} while (sk[top + ] != u);
}
}
bool judge(int a,int b,int c,int d) {
if (b > c && b < d && a < c) return ;
if (a > c && a < d && b > d) return ;
return ;
}
void solve() {
int n = read(), m = read(), cnt = ;
for (int i = ; i <= m; ++i)
g[i].first = read(), g[i].second = read();
for (int i = ; i <= n; ++i) c[i] = read();
if (m > * n - ) { puts("NO"); return ; }
for (int i = ; i <= n; ++i) pos[c[i]] = i;
for (int i = ; i <= m; ++i) {
g[i].first = pos[g[i].first], g[i].second = pos[g[i].second];
if (g[i].first > g[i].second) swap(g[i].first, g[i].second);
if (g[i].second - g[i].first == || (g[i].first == && g[i].second == n)) continue;
g[++cnt] = g[i];
}
m = cnt;
for (int i = ; i <= m; ++i)
for (int j = i + ; j <= m; ++j) {
if (judge(g[i].first, g[i].second, g[j].first, g[j].second)) {
add_edge(i, j + m);
add_edge(i + m, j);
add_edge(j, i + m);
add_edge(j + m, i);
}
}
for (int i = ; i <= m + m; ++i) if (!dfn[i]) tarjan(i);
bool flag = ;
for (int i = ; i <= m; ++i) if (bel[i] == bel[i + m]) flag = ;
puts(flag ? "YES" : "NO");
top = Index = En = tot = ;
for (int i = ; i <= m + m; ++i)
head[i] = dfn[i] = low[i] = bel[i] = ;
}
int main() {
for (int T = read(); T--; ) solve();
return ;
}
1997: [Hnoi2010]Planar的更多相关文章
- BZOJ 1997: [Hnoi2010]Planar( 2sat )
平面图中E ≤ V*2-6.. 一个圈上2个点的边可以是在外或者内, 经典的2sat问题.. ----------------------------------------------------- ...
- Bzoj 1997 [Hnoi2010]Planar题解
1997: [Hnoi2010]Planar Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2224 Solved: 824[Submit][Stat ...
- [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 ...
- [bzoj1997][Hnoi2010]Planar(2-sat||括号序列)
开始填连通分量的大坑了= = 然后平面图有个性质m<=3*n-6..... 由平面图的欧拉定理n-m+r=2(r为平面图的面的个数),在极大平面图的情况可以代入得到m=3*n-6. 网上的证明( ...
- bzoj千题计划231:bzoj1997: [Hnoi2010]Planar
http://www.lydsy.com/JudgeOnline/problem.php?id=1997 如果两条边在环内相交,那么一定也在环外相交 所以环内相交的两条边,必须一条在环内,一条在环外 ...
- [BZOJ1997][Hnoi2010]Planar 2-sat (联通分量) 平面图
1997: [Hnoi2010]Planar Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2317 Solved: 850[Submit][Stat ...
随机推荐
- 计算机网络通信、线程、tcp、udp通信及信号量等读书笔记
一.计算机网络 1.什么是计算机网络:把分布在不同地理位置的计算机与专门的网络设备用通信线路互相连成一个规模大.功能强的系统,从而使众多计算机可以方便地互相传递信息.共享软件.硬件.数据信息等.简单来 ...
- 可以简易设置文字内边距的EdgeInsetsLabel
可以简易设置文字内边距的EdgeInsetsLabel 最终效果: 源码: EdgeInsetsLabel.h 与 EdgeInsetsLabel.m // // EdgeInsetsLabel.h ...
- 理解http请求
HTTP请求的GET方法可以用来抓取网页. HTTP(HyperText Transfer Protocol)是一套计算机通过网络进行通信的规则,计算机专家设计出HTTP,使HTTP客户(如Web浏览 ...
- 铁乐学Python_day04-列表LIST
文:铁乐与猫 2018-3-21 Python内置的一种数据类型是列表:list. list是一种有序的集合,可以随时添加和删除其中的元素. 序列中的每个元素都分配一个数字(下标) - 它的位置,或索 ...
- JXL API总结
API参考: http://www.andykhan.com/jexcelapi/index.html 官网: http://jexcelapi.sourceforge.net/ 1. 创建可写的工作 ...
- Java 处理cookie的方法
一.java创建cookie 方法一: Response.Cookies["userName"].Value = "patrick"; Response.Coo ...
- 【转载】socket 的 connect、listen、accept 和全连接队列、半连接队列的原理
转自:http://blog.csdn.net/tennysonsky/article/details/45621341 写在前面: 1. accept 只是从全连接队列拿出一个已经建立好的socke ...
- 基于easyui开发Web版Activiti流程定制器详解(六)——Draw2d详解(二)
回顾: 上一篇我们介绍了Draw2d整体结构,展示了组件类关系图,其中比较重要的类有Node.Canvas.Command.Port.Connection等,这篇将进一步介绍Draw2d如何使用以及如 ...
- JdkDynamicAopProxy-笔记
这个接口的继承体系图: 一.AopProxy InvocationHandler就不说了,看看AopProxy的源码. /** * Delegate interface for a configure ...
- linux shell基本知识 sleep命令
在有的shell(比如linux中的bash)中sleep还支持睡眠(分,小时) sleep 睡眠1秒 sleep 1s 睡眠1秒 sleep 1m 睡眠1分 sleep 1h 睡眠1小时