Description A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms: dog.gopher gopher.rat rat.tiger aloha.aloha arachnid.dog…
判断一些字符串能首尾相连连在一起 并查集求欧拉回路和通路 Sample Input 3 2 acm ibm 3 acm malform mouse 2 ok ok Sample Output The door cannot be opened. Ordering is possible. The door cannot be opened. #include<cstdio> #include<iostream> #include<algorithm> #include&…
Werewolf Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2363    Accepted Submission(s): 713 Problem Description "The Werewolves" is a popular card game among young people.In the basic ga…
欧拉回路 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15491    Accepted Submission(s): 5921 Problem Description 欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路.现给定一个图,问是否存在欧拉回路?   Input 测试输入包含若干测试用例.每个测试…
原题: http://acm.hdu.edu.cn/showproblem.php?pid=1232 我的第一道并查集题目,刚刚学会,我是照着<啊哈算法>这本书学会的,感觉非常通俗易懂,另外还有一篇同样非常好的博客:http://blog.csdn.net/niushuai666/article/details/6662911 这两位大神已经把并查集讲解的非常透彻了,所以我就不班门弄斧了... 刚开始看到这道题的时候,我并不知道这里是怎么用到并查集的,可以说我对并查集的理解还不是很到位.看了上…
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specification: E…
并查集 题意:找出给定的这些话中是否有冲突.若没有则最多有多少句是对的. /* 思路:如果第x句说y是对的,则x,y必定是一起的,x+n,y+n是一起的:反之x,y+n//y,x+n是一起的. 利用并查集判断 x 和 x+n 是否在同一集合. 至于查找最多正确的话,对这些 “小树” 进行dfs即可. */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #…
这道题还是非常有意思的,题意很简单,就是给定一个图,和图上的双向边,要求1号节点的度(连接边的条数)等于K,求这棵树的生成树. 我们首先要解决,如何让1号节点的度时为k的呢???而且求的是生成树,意思是不是所有边都会选择.那么我们如何选择才能保证1号节点有K个度呢???这里就要考虑联通分量的问题了,我们刨除1号点,那么联通分量的个数,就是我们让图联通的最小个数,因此我们需要用并查集,把点分在不同的联通块内部. 再考虑我们每个联通块,至少需要1条连接1号点的边.不够K再添加连接1号点的边. 然后考…
Problem UVA208-Firetruck Accept:1733  Submit:14538 Time Limit: 3000 mSec  Problem Description The Center City fire department collaborates with the transportation department to maintain maps of the city which reflects the current status of the city str…
纯裸题..写着方便理解... 题意:判断一个无向图是否存在欧拉回路... 解题思路:并查集判断一下是否联通,然后再判断一下点的度数是否为偶数就行了: #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #define maxn 2010 using namespace std; int f[maxn]; int findf(int x) { if(f[x]==x)…