题解: 原先我看错题了,以为是任意选择k个使得它们不矛盾. 这样的话怎么做呢?我想M^2判断,把它们分成若干个集合,集合里面两两不矛盾这个集合里所有的话就不矛盾了. 但是这样是错的.为什么呢? 每一句话实质上都是说明了某两个点同真假或者不同真假.并非两两不矛盾它们就不矛盾,可能是合起来才矛盾. 后来发现题目说的是前k个.. 那么我们就可以像上图一样连边,用并查集判断,如果一个点为真或为假时它的祖先相同,则矛盾了. 代码: #include<cstdio> #include<cstdlib…
Description 约翰有N头奶牛,有一部分奶牛是真话奶牛,它们只说真话,而剩下的是假话奶牛,只说假话.有一天,约翰从奶牛的闲谈中陆续得到了M句话,第i句话出自第Xi头奶牛,它会告诉约翰第Yi头是一头真话奶牛还是假话奶牛.然而,约翰记性不好,他可能把这些话的内容记错了.请检查一下 约翰的记录是否会有矛盾,帮助他找到一个尽量大的K使得约翰记下的前K句话不矛盾. Input Format 第一行:两个整数 N 和 M ,1 ≤ N ≤ 1000; 1 ≤ M ≤ 10000 • 第二行到 M +…
题面 Bzoj 洛谷 题解 最暴力的方法是直接判两个点之间的路径最小值是否\(\geq k\),用\(Dijkstra\)可以做到该算法最快效率,但是空间复杂度始终是\(O(n^2)\)的,会\(MLE\),其实仔细观察一下,会发现对于一个满足某个\(k\)的路径\(dis\),它一定会满足\(\forall k'\leq k\),同时,对于任意一条长度大于\(|dis|\)的路径,它也满足又满足这些\(k\),甚至更多的\(k'\),于是我们从这个性质入手. 具体来说,就是将询问离线化,按照\…
292D - Connected Components D. Connected Components time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We already know of the large corporation where Polycarpus works as a system administrato…
USACO 2013 JAN 一.题目概览 中文题目名称 镜子 栅栏油漆 奶牛排队 英文题目名称 mirrors paint lineup 可执行文件名 mirrors paint lineup 输入文件名 mirrors.in paint.in lineup.in 输出文件名 mirrors.out paint.out lineup.out 每个测试点时限 1秒 1秒 1秒 测试点数目 10 10 10 每个测试点分值 10 10 10 比较方式 全文比较 全文比较 全文比较 二.运行内存限制…
Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which h…
题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despair…
True Liars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16338    Accepted Submission(s): 5724 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Description: After having drifted about in a…
题目链接:http://poj.org/problem?id=1417 True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3851   Accepted: 1261 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore…
After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard…