平面图中E ≤ V*2-6..

一个圈上2个点的边可以是在外或者内, 经典的2sat问题..

------------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
 
using namespace std;
 
#define U(x) U[r[x]]
#define V(x) V[r[x]]
#define H(x) H[r[x]]
 
const int maxn = 20009;
 
struct edge {
int to;
edge* next;
} E[1000000], *pt, *head[maxn];
 
void AddEdge(int u, int v) {
pt->to = v; pt->next = head[u]; head[u] = pt++;
}
 
int Low[maxn], Dfn[maxn], Scc[maxn], CK, scc_n;
int U[maxn], V[maxn], H[maxn], P[maxn], _P[maxn], r[maxn], n;
int N, M, T;
stack<int> S;
 
void Init() {
pt = E;
memset(head, 0, sizeof head);
scanf("%d%d", &N, &M);
for(int i = 0; i < M; i++)
scanf("%d%d", U + i, V + i);
for(int i = 0; i < N; i++) {
scanf("%d", _P + i);
P[_P[i]] = i;
}
for(int i = 0; i < N; i++)
H[_P[i]] = _P[(i + 1) % N];
n = scc_n = CK = 0;
memset(Dfn, 0, sizeof Dfn);
memset(Scc, 0, sizeof Scc);
while(!S.empty()) S.pop();
}
 
bool chk(int l, int r, int _l, int _r) {
if(l > r) swap(l, r);
if(_l > _r) swap(_l, _r);
return (l < _l && _l < r && r < _r) || (_l < l && l < _r && _r < r);
}
 
void Tarjan(int x) {
Dfn[x] = Low[x] = ++CK;
S.push(x);
for(edge* e = head[x]; e; e = e->next) if(!Dfn[e->to]) {
Tarjan(e->to);
Low[x] = min(Low[x], Low[e->to]);
} else if(!Scc[e->to])
Low[x] = min(Low[x], Dfn[e->to]);
if(Dfn[x] == Low[x]) {
int t; scc_n++;
do {
t = S.top(); S.pop();
Scc[t] = scc_n;
} while(t != x);
}
}
 
bool Solve() {
if(M > 3 * N - 6) return false;
for(int i = 0; i < M; i++)
if(V[i] != H[U[i]] && U[i] != H[V[i]]) r[n++] = i;
for(int i = 0; i < n; i++)
for(int j = 0; j < i; j++)
if(chk(P[U(i)], P[V(i)], P[U(j)], P[V(j)])) {
AddEdge(i * 2, j * 2 + 1);
AddEdge(i * 2 + 1, j * 2);
AddEdge(j * 2, i * 2 + 1);
AddEdge(j * 2 + 1, i * 2);
}
for(int i = 0; i < 2 * n; i++) {
if(!Dfn[i]) Tarjan(i);
}
for(int i = 0; i < n; i++)
if(Scc[i * 2] == Scc[i * 2 + 1]) return false;
return true;
}
 
int main() {
scanf("%d", &T);
while(T--) {
Init();
puts(Solve() ? "YES" : "NO");
}
return 0;
}

------------------------------------------------------------------------------------------

1997: [Hnoi2010]Planar

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1183  Solved: 458
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

HINT

Source

BZOJ 1997: [Hnoi2010]Planar( 2sat )的更多相关文章

  1. [BZOJ 1997][HNOI2010]Planar(2-SAT)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1997 分析: 考虑每条边是在圈子里面还是圈子外面 所以就变成了2-SAT判定问题了= ...

  2. bzoj 1997 [Hnoi2010]Planar——2-SAT+平面图的一个定理

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1997 平面图的一个定理:若边数大于(3*点数-6),则该图不是平面图. 然后就可以2-SAT ...

  3. Bzoj 1997 [Hnoi2010]Planar题解

    1997: [Hnoi2010]Planar Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2224  Solved: 824[Submit][Stat ...

  4. bzoj 1997: [Hnoi2010]Planar【瞎搞+黑白染色】

    脑补一下给出的图:一个环,然后有若干连接环点的边,我们就是要求这些边不重叠 考虑一下不重叠的情况,两个有交边一定要一个在环内一个在环外,所以把相交的边连边,然后跑黑白染色看是否能不矛盾即可(可能算个2 ...

  5. bzoj 1997: [Hnoi2010]Planar

    #include<cstdio> #include<cstring> #include<iostream> #define M 20005 #define N 20 ...

  6. [bzoj1997][Hnoi2010]Planar(2-sat||括号序列)

    开始填连通分量的大坑了= = 然后平面图有个性质m<=3*n-6..... 由平面图的欧拉定理n-m+r=2(r为平面图的面的个数),在极大平面图的情况可以代入得到m=3*n-6. 网上的证明( ...

  7. 1997: [Hnoi2010]Planar

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

  8. [BZOJ1997][Hnoi2010]Planar 2-sat (联通分量) 平面图

    1997: [Hnoi2010]Planar Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2317  Solved: 850[Submit][Stat ...

  9. 【BZOJ1997】[Hnoi2010]Planar 2-SAT

    [BZOJ1997][Hnoi2010]Planar Description Input Output Sample Input 2 6 9 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 ...

随机推荐

  1. iOS6 旋转

    iOS 6的rotation改变了很多.先来看看官方的描述  http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/ ...

  2. python-面向对象(二)

    面向对象总结 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使用(可以讲多函数中公用的变量封装到对象中) 对象,根据模板创建的实例( ...

  3. 最终有SpringMvc与Struts2的对照啦

    眼下企业中使用SpringMvc的比例已经远远超过Struts2,那么两者究竟有什么差别,是非常多刚開始学习的人比較关注的问题,以下我们就来对SpringMvc和Struts2进行各方面的比較: 1. ...

  4. CLLocation

    http://blog.sina.com.cn/s/blog_9e8867eb01013knc.html 这家伙写的不错本人也参考了这篇博客,希望原文博主可以谅解新手的无奈举措 首相要提到的类是 CL ...

  5. FTP创建与操作

    1,FTP服务创建于配置http://jingyan.baidu.com/article/0a52e3f4230067bf63ed7268.html, 2,FTP操作类 using System; u ...

  6. VC MFC 屏蔽ESC和ENTER键关闭对话框

    方法一: 窗体头文件中加入: protected: virtual BOOL PreTranslateMessage(MSG* pMsg); // PreTranslateMessage是消息在送给T ...

  7. Java socket字节流传输的示例

    服务端server端: package com.yuan.socket; import java.io.*; import java.net.ServerSocket; import java.net ...

  8. 条件注释+JS实现各版本IE浏览器className

    最近又开始忙了,项目中又遇到了可恶的IE Hack问题,各种Hack的看着让自己都觉得恶心,于是决定改造一番. 首先请出条件注释语句: 之前用过的条件注释 <!--[if lt IE 7]> ...

  9. springmvc入门demo

    目录结构: package com.wyl; import org.springframework.stereotype.Controller; import org.springframework. ...

  10. 你需要了解的JS框架

    excanvas.js/Chart.js/cubism.js/d3.js/dc.js/dx.chartjs.js/echarts.js/flot.js       用途:构建数据统计图表,兼容多浏览器 ...