HDU 4496 d-city--(and application of the check set)

Source: Internet
Author: User

  Give the n points and M edges, one by one to delete the edge, ask each delete after the number of Unicom block.

Analysis: In fact, and check the application of the set, just a while ago has been to do the idea of graph theory has been confined to Tarjan. The method is to record each edge, and then start from the last side of the constant edge, if you use and check the set to determine whether the Unicom block can be reduced.

The code is as follows:

1#include <stdio.h>2#include <string.h>3#include <algorithm>4#include <Set>5 using namespacestd;6typedef pair<int,int>PII;7 8 introot[10000+5],ans[10000+5];9PII edges[100000+5];Ten intFindrootintx) {returnx==root[x]?x:root[x]=Findroot (root[x]);} One  A intMain () - { -     intn,m; the      while(SCANF ("%d%d", &n,&m) = =2) -     { -         intsum =N; -          for(intI=0; i<n;i++) root[i]=i; +          for(intI=0; i<m;i++) -         { +             intu,v; Ascanf"%d%d",&u,&v); atedges[i]=PII (u,v); -         } -  -          for(intj=n-1; i>=0; i--) -         { -Ans[i] =sum; in             intU = edges[i].first,v=Edges[i].second; -             intx = Findroot (u), y =Findroot (v); to             if(X! =y) +             { -ROOT[X] =y; theSum--; *             } $         }Panax Notoginseng          for(intI=0; i<m;i++) -         { theprintf"%d\n", Ans[i]); +         } A     } the     return 0; +}

HDU 4496 d-city--(and application of the check set)

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.