平面图中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. 4.跟我学solr---SolrRequestHandler具体解释

    概述 我们在使用solr admin在做查询的时候,能够看到Request-Hander(qt)输入栏中有"/select"这样一个uri.当我们点击查询的时候所发起的请求是这种. ...

  2. a simple erlang process pool analysis

    a simple erlang process pool analysis 这是一个简单的erlang进程池分析,是learn you some erlang for Great Good 里面的一个 ...

  3. hdu-4468-Spy-KMP+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4468 题目意思: 给你一个串r,求一个串s,使得s的前缀1+s的前缀2+s的前缀3+...+s的前缀 ...

  4. 浅谈Spring(一)

    一.Spring引言 Spring是一款轻量级框架,代码入侵量很小,并且还是众多优秀的设计模式的组合(工厂.代理.模板.策略). 特点: 1.方便解耦,简化开发 通过Spring提供的IoC容器,我们 ...

  5. 查看SQLServer数据库信息的SQL语句

    --查看数据库中的表信息, --包括(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_MSForEachTable @precommand=N'create table # ...

  6. python读取中文文件编码问题

    python 读取中文文件后,作为参数使用,经常会遇到乱码或者报错asii错误等. 我们需要对中文进行decode('gbk') 如我有一个data.txt文件有如下内容: 百度 谷歌 现在想读取文件 ...

  7. (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)

    We have already seen how to make jQuery react to the loading of a web page. The $(document).ready()e ...

  8. SecureCRT, SecureFX连接Linux时中文乱码解决办法

    SecureCRT可以在GUI界面设置,但SecureFX没有设置界面.不过可以直接在配置文件中修改. 1. 找到配置文件夹(选项--全局选项,常规下的配置文件夹),默认是:C:\Documents  ...

  9. mac定时任务

    <?xml version=”1.0″ encoding=”UTF-8″?><!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” ...

  10. qemu/kvm/qemu-kvm/virsh的区别

    转自:http://www.2cto.com/os/201305/209596.html qemu/kvm/qemu-kvm/virsh的区别   qemu是一套虚拟机管理系统,kqemu是qemu的 ...