开始填连通分量的大坑了= =

  然后平面图有个性质m<=3*n-6.....

  由平面图的欧拉定理n-m+r=2(r为平面图的面的个数),在极大平面图的情况可以代入得到m=3*n-6。

  网上的证明(雾?):

 http://blog.chinaunix.net/uid-26510579-id-3183558.html

 http://www.zybang.com/question/673815bbe56e8b5639f95234b515b8c5.html

  这题把哈密顿回路看成圆,就变成圆上的点之间的边是否能不相交。。和某次模拟赛的T3一模一样= =

  显然对于两条会相交的边x,y,x和y既不能同时在圆内,也不能同时在圆外。。。就转换成2-sat问题了。。

  若使x表示x在圆内,x'表示x在圆外,因为x,y不能同时在圆内,所以连上(x,y')和(y,x'),然后还不能同时在圆外,就再连(x',y)和(y',x)。

  然后就是模板了。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const int maxm=;
struct zs{
int too,pre;
}e[maxm];
struct zzs{
int from,too;
}a[maxn*];
int last[maxn**],dfn[maxn**],low[maxn**],st[maxn**],bel[maxn**];
bool ins[maxn**];
int from[maxn*],too[maxn*],id[maxn];
int tot,tim,num,i,j,k,n,m,x,y,top,tt;
inline bool cant(int x,int b){
if(a[x].from>a[b].from)swap(x,b);
if(a[b].from>a[x].from&&a[b].from<a[x].too&&a[b].too>a[x].too)return ;
return ;
}
void insert(int a,int b){
// printf("%d-->%d\n",a,b);
e[++tot].too=b;e[tot].pre=last[a];last[a]=tot;
e[++tot].too=a;e[tot].pre=last[b];last[b]=tot;
}
void tarjan(int x){
dfn[x]=low[x]=++tim;
st[++top]=x;;ins[x]=;
for(int i=last[x];i;i=e[i].pre)if(!dfn[e[i].too]){
tarjan(e[i].too);low[x]=min(low[x],low[e[i].too]);
}else if(ins[e[i].too])low[x]=min(low[x],dfn[e[i].too]);
if(dfn[x]==low[x]){
num++;
while(st[top+]!=x){
ins[st[top]]=;bel[st[top]]=num;
top--;
}
}
}
bool cmp(zzs a,zzs b){
return a.from<b.from||(a.from==b.from&&a.too<b.too);
}
int main(){
scanf("%d",&tt);
while(tt--){
scanf("%d%d",&n,&m);
if(m>n*-){
for(i=;i<=m<<;i++)scanf("%d",&j);
for(i=;i<=n;i++)scanf("%d",&j);
printf("NO\n");continue;
}
top=tim=tot=num=;
memset(dfn,,*(*m+));
memset(last,,*(*m+));
for(i=;i<=m;i++)scanf("%d%d",&a[i].from,&a[i].too); for(i=;i<=n;i++)scanf("%d",&j),id[j]=i;
for(i=;i<=m;i++){
a[i].from=id[a[i].from];a[i].too=id[a[i].too];
if(a[i].from>a[i].too)swap(a[i].from,a[i].too);
}//按哈密顿回路给点重新编号,使1~n依次对应环中的点
sort(a+,a++m,cmp);j=;
for(i=;i<=m;i++){
if(a[i].from+==a[i].too||a[i].too%n+==a[i].from)continue;
j++;
a[j].from=a[i].from,a[j].too=a[i].too;
}
m=j;
for(i=;i<m;i++)for(j=i+;j<=m;j++){
if(cant(i,j))insert(i*,j*-),insert(j*,i*-);//,printf("%d&&&%d\n",i,j);
if(a[j].from>=a[i].too)break;
}
for(i=;i<=*m;i++)if(!dfn[i])tarjan(i);
bool flag=;
for(i=;i<=m;i++)if(bel[i*]==bel[i*-]){flag=;break;
}
if(flag)printf("NO\n");else printf("YES\n");
}
return ;
}

  系统:正在比对你的代码和黄学长的代码。。。。

     找不到差异QAQ

  当然了kpm大爷那场是玩成括号序列。。。。把边的两端点看成是左括号和右括号,那么圆内和圆外分别是一个合法的括号序列。。算括号序列的时候记录一下每条边会与别的哪些边冲突,按冲突关系建图后二分染色就知道是否可能合法了。。。

  感觉也可以两个括号序列一起上。。其中一个出现冲突后就把冲突的那些边都扔到另外一个括号序列里面,如果再冲突就是无解了。。当然了我只是嘴巴选手(跑

1997: [Hnoi2010]Planar

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1093  Solved: 428
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

 

Sample Output

 

HINT

 

Source

Day1

//没有样例差评

[bzoj1997][Hnoi2010]Planar(2-sat||括号序列)的更多相关文章

  1. bzoj千题计划231:bzoj1997: [Hnoi2010]Planar

    http://www.lydsy.com/JudgeOnline/problem.php?id=1997 如果两条边在环内相交,那么一定也在环外相交 所以环内相交的两条边,必须一条在环内,一条在环外 ...

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

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

  3. BZOJ1997 [Hnoi2010]Planar (2-sat)

    题意:给你一个哈密顿图,判断是不是平面图 思路:先找出哈密顿图来.哈密顿回路可以看成一个环,把边集划分成两个集合,一个在环内,一个在外.如果有两条相交边在环内,则一定不是平面图,所以默认两条相交边,转 ...

  4. BZOJ1997 [Hnoi2010]Planar 【2-sat】

    题目链接 BZOJ1997 题解 显然相交的两条边不能同时在圆的一侧,\(2-sat\)判一下就好了 但这样边数是\(O(m^2)\)的,无法通过此题 但是\(n\)很小,平面图 边数上界为\(3n ...

  5. bzoj1997: [Hnoi2010]Planar

    2-SAT. 首先有平面图定理 m<=3*n-6,如果不满足这条件肯定不是平面图,直接退出. 然后构成哈密顿回路的边直接忽略. 把哈密顿回路当成一个圆, 如果俩条边交叉(用心去感受),只能一条边 ...

  6. bzoj1997 [Hnoi2010]Planar——2-SAT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1997 神奇的经典2-SAT问题! 对于两个相交的区间,只能一里一外连边,所以可以进行2-SA ...

  7. 【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 ...

  8. bzoj1997 [HNOI2010]平面图判定Plana

    bzoj1997 [HNOI2010]平面图判定Planar 链接 bzoj luogu 思路 好像有很多种方法过去.我只说2-sat 环上的边,要不在里面,要不在外边. 有的边是不能同时在里面的,可 ...

  9. BZOJ4350: 括号序列再战猪猪侠

    Description 括号序列与猪猪侠又大战了起来. 众所周知,括号序列是一个只有(和)组成的序列,我们称一个括号 序列S合法,当且仅当: 1.( )是一个合法的括号序列. 2.若A是合法的括号序列 ...

随机推荐

  1. Asp.net常用开发方法之DataTable/DataReader转Json格式代码

    public static string JsonParse(OleDbDataReader dataReader) //DataRead转json { StringBuilder jsonStrin ...

  2. Search an Element in an array

    Given an integer array and an element x, find if element is present in array or not. If element is p ...

  3. PHP-无限级分类(迭代法创建)

    $area = array( array('id'=>1,'name'=>'安徽','parent'=>0), array('id'=>2,'name'=>'海淀','p ...

  4. js变量提升与函数提升

    在es6之前,js语言并没有块级作用域,即{}形成的作用域,只有全局作用域和函数作用域,所谓的提升,即是将该变量的声明或者函数的声明提升,举个例子 console.log(global); //und ...

  5. 《重新定义公司 - Google 是如何运营的》重点摘录

      赋能:创意时代的组织原则 未来企业的成功之道,是聚集一批聪明的创意精英,营造合适的氛围和支持环境,充分发挥他们的创造力,快速感知用户需求,愉快地创造响应的产品和服务.未来组织的最重要功能,那就是赋 ...

  6. (一)DOM 常用操作 —— “查找”节点

    在 DOM 树中,如果想要操作一个节点,那么首先要"查找"到这个节点.查找节点的方法由 Document 接口定义,而该接口由 JavaScript 中的 document 对象实 ...

  7. vue2.0父子组件以及非父子组件如何通信

    1.父组件传递数据给子组件 父组件数据如何传递给子组件呢?可以通过props属性来实现 父组件: <parent> <child :child-msg="msg" ...

  8. kafka资料

    https://www.cnblogs.com/the-tops/p/5685955.html

  9. C程序设计语言(第二版)--- 习题选

    1. 解: 2. 解: 3. (分析的好有条理啊!) 4. 解:

  10. 在Eclipse中查看JDK源码的方法

    遇到这个问题是因为想证明Vector中的get()方法是不是用synchronized关键字修饰的来保证线程安全的方法, 于是在Eclipse里面: Vector<Integer> vec ...