【POJ3207】Ikki's Story IV - Panda's Trick【2-SAT】

学习一发2-SAT。

orz这个blog讲得不错。

http://blog.csdn.net/jarjingx/article/details/8521690


(论tarjan到底要不要加在栈中的标记)


/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 2000005, maxm = maxn, maxs = 2000000;

int n, m, head[maxn], cnt, dfn[maxn], low[maxn], clo, belong[maxn], tot;
bool ins[maxn];

struct _edge {
	int v, next;
} g[maxn];

struct _pos {
	int x, y;
} p[maxm];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

inline void add(int u, int v) {
	g[cnt] = (_edge){v, head[u]};
	head[u] = cnt++;
}

int sta[maxs], top = 0;

inline void tarjan(int x) {
	dfn[x] = low[x] = ++clo; ins[x] = 1;
	sta[++top] = x;
	for(int i = head[x]; ~i; i = g[i].next) {
		int v = g[i].v;
		if(!dfn[v]) tarjan(v), low[x] = min(low[x], low[v]);
		else if(ins[v]) low[x] = min(low[x], dfn[v]);
	}
	if(dfn[x] == low[x]) {
		tot++;
		while(1) {
			int u = sta[top--];
			belong[u] = tot;
			ins[u] = 0;
			if(u == x) break;
		}
	}
}

inline bool check() {
	for(int i = (m << 1) - 1; i >= 0; i--)
		if(belong[i] == belong[i ^ 1])
			return 1;
	return 0;
}

int main() {
	n = iread(); m = iread();
	for(int i = 0; i < maxn; i++) head[i] = -1; cnt = 0;
	for(int i = 0; i < m; i++) {
		int x = iread(), y = iread();
		if(x > y) swap(x, y);
		p[i] = (_pos){x, y};
	}

	for(int i = 0; i < m; i++) for(int j = i + 1; j < m; j++)
		if((p[i].x < p[j].x && p[j].x < p[i].y && p[i].y < p[j].y) || (p[j].x < p[i].x && p[i].x < p[j].y && p[j].y < p[i].y)) {
			add(i << 1, j << 1 | 1);
			add(i << 1 | 1, j << 1);
			add(j << 1, i << 1 | 1);
			add(j << 1 | 1, i << 1);
		}

	for(int i = (m << 1) - 1; i >= 0; i--) if(!dfn[i]) tarjan(i);

	if(check()) printf("the evil panda is lying again\n");
	else printf("panda is telling the truth...\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的纺织品企业财务管理系统,源码+数据库+毕业论文+视频演示 在如今社会上,关于信息上面的处理,没有任何一个企业或者个人会忽视,如何让信息急速传递,并且归档储存查询,采用之前的纸张记录模式已经不符合当前使用要求了。所以,对纺织品企业财务信息管理的提升,也为了对纺织品企业财务信息进行更好的维护,纺织品企业财务管理系统的出现就变得水到渠成不可缺少。通过对纺织品企业财务管理系统的开发,不仅仅可以学以致用,让学到的知识变成成果出现,也强化了知识记忆,扩大了知识储备,是提升自我的一种很好的方法。通过具体的开发,对整个软件开发的过程熟练掌握,不论是前期的设计,还是后续的编码测试,都有了很深刻的认知。 纺织品企业财务管理系统通过MySQL数据库与Spring Boot框架进行开发,纺织品企业财务管理系统能够实现对财务人员,员工,收费信息,支出信息,薪资信息,留言信息,报销信息等信息的管理。 通过纺织品企业财务管理系统对相关信息的处理,让信息处理变的更加的系统,更加的规范,这是一个必然的结果。已经处理好的信息,不管是用来查找,还是分析,在效率上都会成倍的提高,让计算机变得更加符合生产需要,变成人们不可缺少的一种信息处理工具,实现了绿色办公,节省社会资源,为环境保护也做了力所能及的贡献。 关键字:纺织品企业财务管理系统,薪资信息,报销信息;SpringBoot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值