Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8170   Accepted: 2784   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old le…
/* 2sat问题 输出任意一组可行解 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> using namespace std; #define N 2100 struct node { int u,v,next; }ff[N],bian[N*N*8]; int…
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1247    Accepted Submission(s): 542Special Judge Problem Description Your old uncle Tom inherited a piece of land from…
转载地址:http://blog.csdn.net/qq172108805/article/details/7603351 /* 2-sat问题,题意:有对情侣结婚,请来n-1对夫妇,算上他们自己共n对,编号为0~~n-1,他们自己编号为0 所有人坐在桌子两旁,新娘不想看到对面的人有夫妻关系或偷奸关系,若有解,输出一组解,无解输出bad luck 思路: 1.根据偷奸关系建图(1h和2h有偷奸关系,建边1h->2w 2h->1w) 2.求强连通分量 3.判断有无解(任一对夫妇不在同一强连通分量…
https://www.luogu.org/problemnew/show/P4174 最大权闭合子图的模板 每个通讯站建一个点,点权为-Pi:每个用户建一个点,点权为Ci,分别向Ai和Bi对应的点连边:然后就可以跑了 方法是: 建新源S和新汇T,从S向所有正权点连边,容量为点权值:从所有负权点向T连边,容量为点权值的相反数:原图中所有边容量设为无穷大 跑S到T最大流 原因:(网上都有,自己研究的也不知道有没有偏差) 找出图的任意一个割,其中: 显然不可能割掉容量为无穷大的边: 割掉一条S到u的…
http://codeforces.com/problemset/problem/274/D 这道题解题思路: 对每一行统计,以小值列作为弧尾,大值列作为弧头,(-1除外,不连弧),对得到的图做拓扑排序即可. 但本题数据较大,所以需要进行缩点,把相同数值的点缩在一起,成为一个新的大点,原先的小值列向大点连接,再由大点向大值列连接,可以减少边数 举例来说,原本取值为1的有4个点,取值为2的有5个点, 不缩点,就需要20条边 缩点,只需要4+1+5=10条边 (不过我还是觉得这个方法有点投机取巧??…
题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclists. Local representatives of motorcyclists, long feuding the cyclists, have decided to sabotage the event. There are   intersections in B…
题目链接: https://vjudge.net/problem/UVA-10305#author=goodlife2017 题目描述 John有n个任务,但是有些任务需要在做完另外一些任务后才能做. 输入 输入有多组数据,每组数据第一行有两个整数1 <= n <= 100 和 m.n是任务个数(标记为1到n),m两个任务直接关系的数量.在此之后,有m行,每行有2个整数i和j,代表任务i必须在任务j之前完成.用n = m = 0结束整个输入. 输出 每一个数据对应一行n个整数,代表任务完成的顺…
BFS模板,记住这5个: (1)针对树的BFS 1.1 无需分层遍历 from collections import deque def levelOrderTree(root): if not root: return q = deque([root]) while q: head = q.popleft() do something with this head node... if head.left: q.append(head.left) if head.right: q.append…
E. Tree Folding 题目连接: http://codeforces.com/contest/765/problem/E Description Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1,…