Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2473
Give two operations:
M x y: Consider X and y as a category.
S x: Separate X into a single category.
The last question is how many classes there are.
And check the set, but with the delete operation. However, and the check set itself does not support the deletion, online said can introduce an ID to represent a point. As if a person on the internet has a lot of trumpet, if this person's trumpet is sealed and permanent can not be solved, but also want to continue to play, then re-build a number, regenerated into an ID, indicating that this ID is the person is good.
Note that you cannot reset the pre value of the original ID at the time of the delete operation.
1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%lld", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineOnenum (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef map<string,int>MSI; $typedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; the - Const intMAXN =2000010; in intPRE[MAXN]; the intID[MAXN]; the intSUM[MAXN]; About intN, M; the intcnt, t; the the intFindintx) { +RT x = = Pre[x]? X:PRE[X] =find (Pre[x]); - } the Bayi voidUniteintXinty) { thex =find (x); they =find (y); - if(x! = y) Pre[y] =x; - } the the intMain () { the //FRead (); the Charcmd[5]; - intA, B, _ =1; the while(~rint (n) && ~rint (m) && n +m) { theCNT = n +Ten; Cls (sum); theRep (i, MAXN) id[i] = i, pre[i] =i;94 W (m) { the Rs (cmd); the if(cmd[0] =='M') { the Rint (a); Rint (b);98 Unite (Id[a], id[b]); About } - if(cmd[0] =='S') {101 Rint (a);102Id[a] = cnt++;103 }104 } theRep (i, n) sum[i] =find (Id[i]);106Sort (sum, sum+n); t = unique (sum, sum+n)-sum;107printf"Case #%d:%d\n", _++, T);108 }109Rt0; the}
[HDOJ2473] Junk-mail Filter (and check set, delete operation, waistcoat)