"and check set" LA3644 x-plosivesThe set of n elements applies to the problem--and check the set.
Main TopicLoading, the compound consisting of two elements is loaded into the car in the order of input, if an explosion occurs (
There are k simple compounds that contain exactly k elements), record, output the total number of compounds that cannot be loaded.
talk about the idea.How do you understand that "there are k simple compounds that contain just k elements"? Each compound is apportioned to 1/2 elements at the apex, looping! Root node is the same! The problem is all equivalent! Think about the lookup and merge operations of the collection, counting the same sides of the root node during the merge process ~
Reference Code
#include <bits/stdc++.h>using namespace STD;Const int_max =1e5+Ten;intA,b,pre[_max],ans;voidInit () {//The set where each point resides is initialized to itself for(inti =1; I <= _max;++ i) pre[i] = i;}intFindintx) {//Lookup, returns the root node of element x returnPRE[X] = = x? X:pre[x]=find (Pre[x]);}voidJoinintAintb) {//Merger intx = Find (a), y = find (b);if(x! = y) pre[x] = y;Elseans++;//Plus (A, b) ring, explosion booooom!}intMain () {#ifndef Online_judgeFreopen ("Input.txt","R", stdin);#endif //Online_judge while(scanf("%d", &a) = =1) {init (); Ans =0; while(A! =-1){scanf("%d", &b); Join (A, b);scanf("%d", &a); }printf("%d\n", ans); }return 0;}
- Bold
Ctrl + B
- Italic Body
Ctrl + I
- Reference
Ctrl + Q
- Insert Link
Ctrl + L
- Inserting code
Ctrl + K
- Insert Picture
Ctrl + G
- Promote title
Ctrl + H
- Ordered list
Ctrl + O
- Unordered list
Ctrl + U
- Line
Ctrl + R
- Revoke
Ctrl + Z
- Redo
Ctrl + Y
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"And check set" LA3644 x-plosives