https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4922 题意是给定一颗森林,然后每次都可以删除一条边,或者询问某两个点是否连通. 如果顺着做是不行的.因为并查集路径压缩了,是删不了边的,(据说不路径压缩能AC,) 所以考虑逆向操作.首先不能把已经删除了的边加进去森林里面,先处理出最终状态,然后倒着模拟,就能把删边操作等价于变…
Cutting Tree 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4922 Description Tree in graph theory refers to any connected graph (of nodes and edges) which has no simple cycle, while…
题意:       给你一个图,问你删除一些边后还有几个连通快.. 思路:       典型的并查集删边操作,并查集的删边就是先把不删除的边并查集一边(本题没有不删除的边),然后逆序吧所有要删除的边以点点加到并查集数组里,如果当前的边的两个点不是一个集合的,那么删除当前边后就会使连通快加一... #include<stdio.h> #include<string.h> #define N 11000 typedef struct { int a ,b ,c; }EDGE; int…
Problem Description Recognizing junk mails is a tough task. The method used here consists of two steps:1) Extract the common characteristics from the incoming email.2) Use a filter matching the set of common characteristics extracted to determine whe…
UVA 11987 - Almost Union-Find 题目链接 题意:给定一些集合,操作1是合并集合,操作2是把集合中一个元素移动到还有一个集合,操作3输出集合的个数和总和 思路:并查集,关键在于操作2,对于并查集,要去除掉一个结点,假设该结点不是根那就好办了,那么就多开n个结点,每一个结点初始父亲都是它的i + n,这样在移动的时候,就不用操心他是根结点了剩下就是普通的带权并查集了 代码: #include <cstdio> #include <cstring> const…
[题目]:(地址:) http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97671#problem/E [题意]: 给出多棵树和两类操作:操作(C  x)删除结点 x 与其父结点的连边:操作(Q a b)询问 a b 是否连通. [解题思路]: 连通性的查询容易想到用并查集,关键在于如何处理删边. 考虑到删边的难点在于查询时的路径压缩导致某些结点与其父结点"不直接相连",这里使用离线处理,在查询之前把所有该删的边删除,同时逆序处…
总体来说,这个题给的时间比较长,样例也是比较弱的,别的方法也能做出来. 我第一次使用的是不合并路径的并查集,几乎是一种暴力,花了600多MS,感觉还是不太好的,发现AC的人很多都在300MS之内的过得. 看到他们的做法后,我知道了这个题比较好的做法. 逆向思维的并查集,因为这里只有去边操作,完全可以离线计算,把删边当成加边,然后逆序输出答案即可. 但是,这个却有一个坑,很坑,只有第一次删除的时候,我们才对他进行操作,加边的时候也只能在第一次删除的时候加.当时因为这里,十分困惑-- 这是我无路径压…
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16702    Accepted Submission(s): 3761 Problem Description A tree is a well-known data structure that is either empty (null, void, n…
Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26002   Accepted: 8879 Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edge…
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tre…