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 whether…
思路跟 LA 6187 完全一样. 我是乍一看没反应过来这是个并查集,知道之后就好做了. d[i]代表节点 i 到根节点的距离,即每次的sum. #include <cstdio> #include <cstring> #include <cstdlib> ; int N, Q; int p[MAXN]; int d[MAXN]; int FindSet( int x ) { if ( p[x] == x ) return x; int root = FindSet(…
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6276 Accepted Submission(s): 1981 Problem Description Recognizing junk mails is a tough task. The method used here consists o…
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8640 Accepted Submission(s): 2735 Problem Description Recognizing junk mails is a tough task. The method used here consists…
题目传送门 题意:训练指南P246 分析:主要是第二种操作难办,并查集如何支持删除操作?很巧妙的方法:将并查集树上p的影响消除,即在祖先上(sz--, sum -= p),然后为p换上马甲:id[p] = ++pos(可多次),这样id[p]就相当于是新的一个点,那么在Find(x)寻找祖先时要用x的马甲来寻找,即Find (id[x]). #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int rt[N…
题目大意:输入两个整数n,m(n表示点的个数,m表示操作数).在接下来的m行中,对点的操作有两种 1)M a b . 表示将a.b并到一个集合中 2)S a .表示将a从原来的集合中去除,而成为一个单独的集合 解题思路:并查集 1) 解题思路:并查集,M代表合并,S代表删除,下面讲一下删除操作 大家都知道合并操作就是找到找到两个节点的父亲,修改父亲,如果删除就是将该点的父亲重新设置成自己,这样行不行呢? 这是不行的,比如1,2,3的父亲都是1,现在删除1,1的父亲还是1,2,3也是1,集合还是1…
True Liars Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2713 Accepted: 868 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 exha…
UVA - 11987 Almost Union-Find I hope you know the beautiful Union-Find structure. In this problem, you’re to implement something similar, but not identical. The data structure you need to write is also a collection of disjoint sets, supporting 3 oper…
题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a professional tree manager is needed. Your task is to write a program to help manage the trees. Initially, there are n forests and for the i-th forest the…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4384 Accepted Submission(s): 1673 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2818 题意:有N个块,每次有两个操作: M x y表示把x所在的那一堆全部移到y所在的那一堆的下方. C x 询问在x下方有多少个方块. 用并查集,在路径压缩的时候后序更新当前块下有多少个其他块,注意这里“当前块下”其实和并查集是相反的,也就是父亲节点在儿子下面. 需要额外维护一个量:某一堆的块的总数,这个在unite操作的时候,如果不是同一个根,直接将一部分加到另一部分上就可以. /* ━━━━━…