平面图中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. Doctype 严格模式与混杂模式-如何触发这两种模式,区分它们有何意义?

    Doctype:(Document Type)文档类型,它位于文档中最前面的位置,处于标签之前.如果你想制作符合标准的页面,一个必不可少的关键组成部分就是DOCTYPE的声明.确定了正确的Doctyp ...

  2. discuz函数quote

    public static function quote($str, $noarray = false) { if (is_string($str)) return '\'' . addcslashe ...

  3. oracle导入导出exp,imp

    exp dadifilm/oracle@dg file=/tmp/dadi.dmp full=y imp u_data/321@dg1  file=/dadi_desc.dmp Import: Rel ...

  4. Python文件或目录操作的常用函数

    ◆ os.listdir(path) Return a list containing the names of the entries in the directory given by path. ...

  5. AJAX - 创建 XMLHttpRequest 对象

    XMLHttpRequest 是 AJAX 的基础. XMLHttpRequest 对象 所有现代浏览器均支持 XMLHttpRequest 对象(IE5 和 IE6 使用 ActiveXObject ...

  6. PHP删除HTMl标签

    /** * 取出html标签 * * @access public * @param string str * @return string * */ function deletehtml($str ...

  7. spring mvc 简单搭建

    文中用的框架版本:spring 3,hibernate 3,没有的,自己上网下. web.xml配置: </load-on-startup>     </servlet>    ...

  8. Aho - Corasick string matching algorithm

    Aho - Corasick string matching algorithm 俗称:多模式匹配算法,它是对 Knuth - Morris - pratt algorithm (单模式匹配算法) 形 ...

  9. BZOJ 1037: [ZJOI2008]生日聚会Party( dp )

    dp(i, j, a, b)表示选了i个男生, j个女生, 后缀中男生比女生多a(最多), 女生比男生多b(最多). dp(i+1, j, a+1, max(0, b-1)) += dp(i, j, ...

  10. Hibernate学习之hibernate执行顺序

    Hibernate 执行的顺序如下:  (1) 生成一个事务的对象,并标记当前的 Session 处于事务状态(注:此时并未启动数据库级事务).  (2) 应用使用 s.save 保存对象,这个时候  ...