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)