"And check set" LA3644 x-plosives

Source: Internet
Author: User

"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
    • ReferenceCtrl + Q
    • Insert LinkCtrl + L
    • Inserting codeCtrl + K
    • Insert PictureCtrl + G
    • Promote titleCtrl + H
    • Ordered listCtrl + O
    • Unordered listCtrl + U
    • LineCtrl + R
    • RevokeCtrl + Z
    • RedoCtrl + Y

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"And check set" LA3644 x-plosives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.