HDU 4587-NODES enumeration + Cut Point

Source: Internet
Author: User

Original title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4587

NODES

Time limit:24000/12000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 1448 Accepted Submission (s): 441


Problem Descriptionsuppose That's an undirected graph, and the value of Stabis defined as follows:

Among the Expression,g-i,-j is the remainder after removing node I, node J and all edges that's directly relevant to th e Previous and nodes. cntcompentis the number of connected components of X independently.
Thus, given a certain undirected graph G, you is supposed to calculating the value of Stab.

Inputthe input would contain the description of several graphs. For each graph, the description consist of a integer N for the number of nodes, a integer M for the number of edges, and M pairs of integers for edges (3<=n,m<=5000).
Please note the endpoints of the edge are marked in the range of [0,n-1], and input cases ends with EOF.

Outputfor each graph in the input, you should output the value of Stab.

Sample INPUT4 50 11 22 33 00 2

Sample Output2

SOURCE2013 ACM-ICPC Nanjing Division National Invitational--re-title

Recommendzhuyuanchen520 Test Instructions

I'll give you a picture of the maximum number of connected blocks you can get after removing two points.

Exercises

First enumerate one of the points, and then in the remaining points to cut points, tarjan when the statistics of each cut point split several connected blocks, take a maximum cut point, and then DFS once to find the number of connected blocks.

Code
#include <cstdio>#include<iostream>#include<vector>#include<cstring>#include<algorithm>#defineMax_n 5555using namespaceStd;vector<int>G[max_n];BOOLVis[max_n];intDfn[max_n],low[max_n],ind=0;intCut[max_n];intnode;voidTarjan (intUintp) {    intChild=0; Dfn[u]=low[u]=++IND; Vis[u]=1;  for(intI=0; I<g[u].size (); i++){        intv=G[u][i]; if(v==p| | V==node)Continue; if(!Vis[v])            {Tarjan (v,u); Low[u]=min (low[v],low[u]); Child++; if((p==-1&&child>1)|| (p!=-1&&low[v]>=Dfn[u])) Cut[u]++; }        ElseLow[u]=min (dfn[v],low[u]); }}intn,m;voidinit () { for(intI=0; i<=n;i++) g[i].clear (); IND=0; memset (Vis,0,sizeof(VIS)); memset (Cut,0,sizeof(Cut));}BOOLUsed[max_n];intcu;voidDfsintUintp) {    if(u==p| | used[u]| | u==node| | U==CU)return; Used[u]=1;  for(intI=0; I<g[u].size (); i++) DFS (g[u][i],u);}intMain () { while(SCANF ("%d%d", &n,&m) = =2){        intstab=1;        Init (); intu,v;  for(intI=0; i<m;i++) {scanf ("%d%d", &u, &v);            G[u].push_back (v);        G[v].push_back (U); }         for(intI=0; i<n;i++) {node=i; memset (Vis,0,sizeof(VIS)); IND=0; memset (Cut,0,sizeof(cut));  for(intj=0; j<n;j++)                if((!vis[j]) &&j!=node) Tarjan (J,-1); intMaxc=0;  for(intj=0; j<n;j++)                if(j!=node&&cut[j]>=MaxC) {cu=J; MaxC=Cut[j]; }            intans=0; memset (Used,0,sizeof(used));  for(intj=0; j<n;j++)                if((!used[j]) &&j!=node&&j!=cu) {DFS (J,-1); Ans++; } Stab=Max (Stab,ans); } printf ("%d\n", Stab); }    return 0;}

HDU 4587-NODES enumeration + Cut Point

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.