"Bomb-eating pigeon uva10765-double unicom template"

Source: Internet
Author: User

• Once there was a pigeon lence, it ate a bomb, then someone out of the problem.

• English questions, to the effect:

give a connected undirected graph, find out: For each point, delete this point (and its connected edge after), the current graph of the number of connected blocks, this value as the lence value of the point. The output is based on the first m points of the lence value from large to small (from small to large) and its lence value.

Analysis

For connected block problems, there are three ways to find it:

① ga (gabow) ② algorithm (Tarjan) ③kosaraju algorithm.

Here the rice cake uses the Tarjan algorithm.

• What do you do? Find and Mark two connected components.

The meaning of a double-connected component (which is referred to as the Edge-connected component) is found in the undirected graph: Even if you eat a point arbitrarily, the points can still reach each other, the so-called connected block. If we divide a graph into multiple double-link components, this is the case:

• For easy viewing, use a pinch-point operation. That's it:

• Therefore, our approach is to classify the points according to their location. If this point is not connected to the bridge, then the entire graph is still unicom. If the point is connected to a bridge, let's guess it's connected to several bridges (not a guess, seriously!). ), then its destruction will lead to the destruction of these bridges, the destruction of each bridge will make a dual-link component out of the original image, so: If this point connected to the Num Bridge, then now this figure is a wind and rain drift in the (num+1) part.

• Note that in actual processing, we are using an array to record the number of bridges connected to each point, so if this is not connected to the bridge then it is 0 and the final answer is 0+1=1, so no special handling is required. Wonderful template is drawing closer!

1#include <stdio.h>2#include <algorithm>3#include <cstring>4 #defineGo (i,a,b) for (int i=a;i<=b;i++)5 #defineFo (i,a,x) for (int i=a[x],v=e[i].v;i;i=e[i].next,v=e[i].v)6 #defineMem (A, B) memset (A,b,sizeof (a))7 using namespaceStdConst intn=10003;8 structe{intV,next;} e[n* -];structa{intU,val;} Ans[n];BOOLCut[n];9 intN,m,head[n],k,low[n],dfn[n],t,dfs_clock;Ten BOOLCMP (A A,a b) {returnA.val==b.val?a.u<b.u:a.val>B.val;} One voidADD (intUintV) {e[k]= (e) {v,head[u]};head[u]=k++;} A voidTarjan (intUintFA) - { -Low[u]=dfn[u]=++dfs_clock;intnum=0, kids=0; theFo (i,head,u)if(V!=FA) {if(!Dfn[v]) -     { -kids++; Tarjan (v,u); low[u]=min (low[u],low[v]); -         if(Dfn[u]<=low[v]) num++,cut[u]=1;}//wrongly written low[u] +         Elselow[u]=min (low[u],dfn[v]); -     } +     if(!fa&&kids==1) cut[u]=0, num=0; ans[++t]=(A) {u,num}; A } at intMain () { while(SCANF ("%d%d", &n,&m) &&N) - { -Mem (Head,0); Mem (Low,0); Mem (DFN,0); Mem (Cut,0); t=dfs_clock=0; k=1;intu,v; -      while(SCANF ("%d%d", &u,&v) &&++u&&++v)    Add (U,v), add (V,u);  -Go (i,1, N)if(!dfn[i]) Tarjan (I,0); Sort (ans+1, ans+t+1, CMP); -Go (i,1, m) printf ("%d%d\n", ans[i].u-1, ans[i].val+1); inPuts"");}return 0;}//Paul_guderian

Let me, feel embarrassed, is the freedom of struggle. ———— Lei "Chengdu"

"Bomb-eating pigeon uva10765-double unicom template"

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.