Code:

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=3000;
int c=0;
int mark[maxn],S[maxn],from[maxn],to[maxn];
vector<int>G[maxn];
void add_edge(int x,int y){
x=(x*2)+1,y=(y*2)+1;
G[x-1].push_back(y); //里->外
G[y-1].push_back(x); //里->外
G[x].push_back(y-1); //外->里
G[y].push_back(x-1); //外->里
}
void build(int m){
for(int i=0;i<m-1;++i)
for(int j=i+1;j<m;++j)
if((from[j]<from[i]&&to[j]<to[i]&&to[j]>from[i])||(from[i]<from[j]&&to[i]<to[j]&&to[i]>from[j]))
add_edge(i,j);
}
int dfs(int x)
{
if(mark[x^1])return 0;
if(mark[x])return 1;
mark[x]=1;
++c;
S[c]=x;
int siz=G[x].size();
for(int i=0;i<siz;++i)
if(!dfs(G[x][i]))return 0;
return 1;
}
int solve(int m)
{
for(int i=0;i<m*2;i+=2){
if(!mark[i]&&!mark[i+1])
{
c=0;
if(!dfs(i))
{
while(c>0)
{
mark[S[c]]=0;
c-=1;
}
if(!dfs(i+1))return 0;
}
}
}
return 1;
}
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<m;++i){
int a,b;
scanf("%d%d",&a,&b);
from[i]=min(a,b);
to[i]=max(a,b);
}
build(m);
if(solve(m))printf("panda is telling the truth...");
else printf("the evil panda is lying again");
return 0;
}

Ikki's Story IV - Panda's Trick POJ - 3207_dfs跑2-SAT的更多相关文章

  1. Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)

    题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...

  2. POJ 3207 Ikki's Story IV - Panda's Trick

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7296   ...

  3. poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)

    http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 13 ...

  4. POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)

    POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...

  5. POJ 3207 Ikki's Story IV - Panda's Trick (2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6691   ...

  6. 【POJ3207】Ikki's Story IV - Panda's Trick

    POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...

  7. 【POJ】3207 Ikki's Story IV - Panda's Trick

    http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边.问是否存在这些边不相交的方案.( ...

  8. POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)

    题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...

  9. POJ Ikki's Story IV - Panda's Trick [2-SAT]

    题意: 圆上n个点,m对点之间连边,连在园内或园外,所有边不相交是否可行 发现两对点连线都在内相交则都在外也相交,那么只有一个在内一个在外啦,转化为$2-SAT$问题 #include <ios ...

随机推荐

  1. jQuery动态效果

    1.一号店首页 2.淘宝网购物车

  2. Java EE: XML Schemas for Java EE Deployment Descriptors(Java Web的web.xml头web-app标签上的XML模式)

    继上几篇文章 http://www.cnblogs.com/EasonJim/p/6221952.html http://www.cnblogs.com/EasonJim/p/6959120.html ...

  3. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. 数据结构之---C++语言实现图的十字链表存储表示

    近期一直忙着考研复习,非常久都没有更新博客了.今天写一篇数据结构的存储. //有向图的十字链表存储表示 //杨鑫 #include <iostream> #include <cstd ...

  5. 开源项目 apk cfg and android app path profiling

    暑假里面完毕的一个小项目,limitation还是挺多的. 期待未来有更大的motivation 去完好它.通过此次的项目设计,对于smali的语法更加了解了,对于进一步学习android app的安 ...

  6. Spring+EhCache缓存实例(具体解说+源代码下载)

    一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有高速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...

  7. 2016.04.07,英语,《Vocabulary Builder》Unit 11

    cant, from the Latin verbs canere and cantare, meaning 'sing'. by way of French, add an h to the roo ...

  8. Oracle 与 MySql 区别

    一.并发性 并发性是oltp数据库最重要的特性,但并发涉及到资源的获取.共享与锁定. mysql:mysql以表级锁为主,对资源锁定的粒度很大,如果一个session对一个表加锁时间过长,会让其他se ...

  9. c28---const

    // // main.c // const关键字,节省内存空间,放在字符表里面, #include <stdio.h> int main(int argc, const char * ar ...

  10. 深入Session

    早上考虑Spring MVC和Structs2项目共用时看到一个问题,如何保持session一致?Session是怎么样被服务器处理的呢,Spring MVC中是如何封装处理Session并在不同请求 ...