题目链接

BZOJ1997

题解

显然相交的两条边不能同时在圆的一侧,\(2-sat\)判一下就好了

但这样边数是\(O(m^2)\)的,无法通过此题

但是\(n\)很小,平面图 边数上界为\(3n - 6\),所以过大的\(m\)可以判掉

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdio>
  5. #include<cmath>
  6. #include<map>
  7. #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
  8. #define REP(i,n) for (int i = 1; i <= (n); i++)
  9. #define mp(a,b) make_pair<int,int>(a,b)
  10. #define cls(s) memset(s,0,sizeof(s))
  11. #define cp pair<int,int>
  12. #define LL long long int
  13. using namespace std;
  14. const int maxn = 10005,maxm = 8000005,INF = 1000000000;
  15. inline int read(){
  16. int out = 0,flag = 1; char c = getchar();
  17. while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
  18. while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
  19. return out * flag;
  20. }
  21. int h[maxn],ne;
  22. struct EDGE{int to,nxt;}ed[maxm];
  23. int n,m,N,pos[maxn],a[maxn],b[maxn],vis[maxn];
  24. int dfn[maxn],low[maxn],Scc[maxn],st[maxn],scci,cnt,top;
  25. inline void build(int u,int v){ed[++ne] = (EDGE){v,h[u]}; h[u] = ne;}
  26. void dfs(int u){
  27. dfn[u] = low[u] = ++cnt;
  28. st[++top] = u;
  29. Redge(u){
  30. to = ed[k].to;
  31. if (!dfn[to]){
  32. dfs(to);
  33. low[u] = min(low[u],low[to]);
  34. }
  35. else if (!Scc[to]) low[u] = min(low[u],dfn[to]);
  36. }
  37. if (dfn[u] == low[u]){
  38. scci++;
  39. do {
  40. Scc[st[top]] = scci;
  41. }while (st[top--] != u);
  42. }
  43. }
  44. int main(){
  45. int T = read();
  46. while (T--){
  47. n = read(); m = read();
  48. REP(i,m) a[i] = read(),b[i] = read(),vis[i] = false;
  49. REP(i,n) pos[read()] = i;
  50. if (m > 3 * n - 6) {puts("NO"); continue;}
  51. REP(i,m){
  52. a[i] = pos[a[i]]; b[i] = pos[b[i]];
  53. if (a[i] > b[i]) swap(a[i],b[i]);
  54. if (a[i] + 1 == b[i]) vis[i] = true;
  55. }
  56. int tmp = m; m = 0;
  57. REP(i,tmp) if (!vis[i]){
  58. m++;
  59. a[m] = a[i]; b[m] = b[i];
  60. }
  61. N = (m << 1); REP(i,N) h[i] = 0; ne = 0;
  62. int x,y,xx,yy;
  63. for (int i = 1; i <= m; i++){
  64. x = a[i]; y = b[i];
  65. for (int j = i + 1; j <= m; j++){
  66. xx = a[j]; yy = b[j];
  67. if ((x < xx && xx < y && yy > y) || (x < yy && yy < y && xx < x)){
  68. build(i,j + m); build(j + m,i);
  69. }
  70. }
  71. }
  72. cnt = scci = top = 0;
  73. REP(i,N) dfn[i] = low[i] = Scc[i] = 0;
  74. REP(i,N) if (!dfn[i]) dfs(i);
  75. int flag = true;
  76. REP(i,m) if (Scc[i] == Scc[i + m]){
  77. flag = false; break;
  78. }
  79. puts(flag ? "YES" : "NO");
  80. }
  81. return 0;
  82. }

BZOJ1997 [Hnoi2010]Planar 【2-sat】的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. bzoj1997: [Hnoi2010]Planar

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

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

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

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

  9. 【刷题】BZOJ 2001 [Hnoi2010]City 城市建设

    Description PS国是一个拥有诸多城市的大国,国王Louis为城市的交通建设可谓绞尽脑汁.Louis可以在某些城市之间修建道路,在不同的城市之间修建道路需要不同的花费.Louis希望建造最少 ...

随机推荐

  1. WCF中数据契约之已知类型的几种公开方式

    WCF中传输的数据不想传统的面向对象编程,它只传递了一些对象的属性,但是自身并不知道自己属于什么对象,所以,他没有子类和父类的概念,因而也就没有Is-a的关系,所以在WCF中,如果想维持这种继承关系, ...

  2. Appium 运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for (转)

    现象:Appium运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported f ...

  3. GitHub 多人协作开发 三种方式:

    GitHub 多人协作开发 三种方式: 一.Fork 方式 网上介绍比较多的方式(比较大型的开源项目,比如cocos2d-x) 开发者 fork 自己生成一个独立的分支,跟主分支完全独立,pull代码 ...

  4. Tensorflow基本开发架构

    Tensorflow基本开发架构 先说句题外话, 这段时间一直研究爬虫技术,主要目的是为将来爬取训练数据做准备,同时学习python编程.这一研究才发现,python的开发资源实在是太丰富了,所有你能 ...

  5. [转]50 Tips for Working with Unity (Best Practices)

    About these tips These tips are not all applicable to every project. They are based on my experience ...

  6. 1035 Password (20 分)(字符串)

    注意下单复数 #include<bits/stdc++.h> using namespace std; pair<string,string>pa; int main() { ...

  7. Python常用模块之Pygame(手册篇:首页)

    Pygame手册官方网址:http://www.pygame.org/docs/ Pygame首页 说明文档: 自述 关于Pygame的基本信息,它是什么,谁参与了以及在哪里找到它. 安装 在几个平台 ...

  8. HttpServlet 详解(基础)

    HttpServlet详解 大家都知道Servlet,但是不一定很清楚servlet框架,这个框架是由两个Java包组成:javax.servlet和javax.servlet.http. 在java ...

  9. oracle时间转换查询

    查询oracle 数据库时要查询某一字段的最大时间或者最小时间,因为oracle的时间点 精确到毫秒 甚至更高精度级别 根据字段来转换成对应的时间格式: SELECT TO_CHAR(MAX(crea ...

  10. 作业要求20181016-3 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 01

    此次作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 Scrum master:范洪达 一.小组介绍 组长:王一可 组员 ...