一条边<u,v>表示u选那么v一定被选. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; ; ; struct EDGE{int to,next;}edge[Maxm]; int T,m,Stack[Maxn],head[Maxn],Belong[Maxn],Id[Maxn],Dfn[Maxn],L…
题目链接:http://poj.org/problem?id=3678 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; ; struct Two_Sat { int n; vector<]; ]; ],cnt; void init(int n) { this-…
题意: 有n个未知量,m对未知量之间的关系,判断是否能求出所有的未知量且满足这些关系 解析: 关系建边就好了 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include <set> #include <vector> #include &…
题目链接:HDU - 3062 有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席.在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在聚会上的.有没有可能会有n 个人同时列席? Input n: 表示有n对夫妻被邀请 (n<= 1000)m: 表示有m 对矛盾关系 ( m < (n - 1) * (n -1))在接下来的m行中,每行会有4个数字,分别是 A1,A2,C1,C2 A1,A2分别表示是夫妻的编号 C1,C2 表…
Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integ…
最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是字典树和KMP的结合,然后去思考一下KMP的原理,然后就是在字典树上实现KMP 这里最重要的思想可能就是fail的思想,就像KMP一样,匹配失败后,有一个next的数组去回溯(最长公共前缀后缀) 如何理解了KMP的话,感觉这个不会很难理解,字典树是一个非常简单的东西就不用讲了吧. HDU - 222…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3062 思路:根据矛盾关系连边(如果a与b矛盾,则连边a'->b,b'->a),然后强连通缩点,判断同一对夫妻是否在同一个连通分量中,如果是,则不能同时列席,否则可以. 2-sat学习资料:http://wenku.baidu.com/view/b96a07d9ce2f0066f533226c.html http://paste.ubuntu.com/5972060/ 题目链接:http://acm…
这几个题练习DFS序的一些应用. 问题引入: 给定一颗n(n <= 10^5)个节点的有根树,每个节点标有权值,现有如下两种操作: 1.C x y     以节点x的权值修改为y. 2.Q x       求出以节点x为根的子树权值和. 最直观的做法, 枚举一个子树内所有节点的权值加和.但这种做法的每一次讯问的时间复杂度是O(n)的,很明显无法满足题目的需要,我们需要更优的解法. 我们考虑DFS序的另外一种形式,当访问到一个节点时记下当前的时间戳,我们设它为L[x],  结束访问一个节点时当前的…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3062 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 1250 #define INF 0…
hdu 2544  求点1到点n的最短路  无向图 Sample Input2 1 //结点数 边数1 2 3 //u v w3 31 2 52 3 53 1 20 0 Sample Output32 堆优化Dijstra模板 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include &…