平面图中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. Codeforces 707D Persistent Bookcase(时间树)

    [题目链接] http://codeforces.com/problemset/problem/707/D [题目大意] 给出一个矩阵,要求满足如下操作,单个位置x|=1或者x&=0,一行的数 ...

  2. PHPExcel 多工作表 导出

    //浏览器输出excel header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ...

  3. poj1799---解析几何

    sin(a)=r/R-r,反三角asin(r/R-r),乘以2n=2pi,去化简,得到r 收获:define pi acos(-1) 这样pi的精度会高很多<math.h>(cos,sin ...

  4. javascript数组去重算法-----4

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. mongoose 查询子文档的方法

    { "__v": 1, "_id": "538f5f0f6195a184108c8bd8", "title": &quo ...

  6. c++基础 之 面向对象特征一 : 继承

    class Base { public: void f() { cout<<"void f()"<<endl<<endl; } void f(i ...

  7. ActiveMQ使用STOMP协议的一个错误问题:Unexpected ACK received for message-id

    使用某些语言环境下的stomp包(比如php python ruby),可能会出现如下问题: Unexpected ACK received for message-id 这一般可能有两个原因. 1. ...

  8. [转载]VMWare网络连接透析

    http://blog.csdn.net/struggleyb/article/details/1102214 以前在学校,VMWare里面的Gentoo Linux是采用network bridge ...

  9. BZOJ 2879: [Noi2012]美食节( 费用流 + 动态加边 )

    倒着做菜..然后考虑为当前的人做菜对后面的人的影响就可以了..要动态加边 --------------------------------------------------------------- ...

  10. 个人笔记mysql游标

    经过测试,mysql游标是无法读取自定义函数计算的结构,mysql自带的函数计算值是可以读取的.