Question Description |
Ask a figure to delete a point, the maximum number of Unicom block. |
Input |
Multiple sets of data. The first line, two integers p,c, represents the number of points and sides. The next line of C is two integers per line p1,p2, indicating that P1 and P2 have side connections, guaranteeing no heavy edges. The read-in ends with 0 0. |
Output |
Outputs several rows, representing the results of each group of data. |
Input example |
3 3 0 1 0 2 2 1 4 2 0 1 2 3 3 1 1 0 0 0 |
Output example |
1 2 2 |
Other Notes |
Data range and hints 1≤p≤10000,c≥0,0≤p1,p2<p |
Cutting edge of the board
No, No. here: https://www.cnblogs.com/WWHHTT/p/9745499.html
Record each point and add a few more unicom blocks after it's removed.
and add to the original number.
The following code is given:
#include <iostream>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<cstdio>#include<cstdlib>using namespaceStd;inlineintRd () {intx=0, f=1; CharCh=GetChar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; returnx*F;} InlinevoidWriteintx) { if(x<0) Putchar ('-'), x=-x; if(x>9) Write (x/Ten); Putchar (x%Ten+'0'); return ;}intn,m;inthead[100006];intnxt[200006],to[200006];intTotal=0;voidAddintXinty) { Total++; To[total]=y; Nxt[total]=Head[x]; HEAD[X]=Total ; return ;}intdfn[100006],low[100006];inttot=0;intnum[100006];voidTarjan (intXintFA) {Dfn[x]=low[x]=++tot; for(intE=head[x];e;e=Nxt[e]) { if(!Dfn[to[e]]) {Tarjan (to[e],x); LOW[X]=min (low[x],low[to[e]]); if(Low[to[e]]>=dfn[x]) num[x]++; } Else if(TO[E]!=FA) low[x]=min (low[x],dfn[to[e]]); } return ;}intMain () { while(1) {memset (DFN,0,sizeof(DFN)); memset (Head,0,sizeof(head)); memset (num,0,sizeof(num)); Total=tot=0; N=Rd (); M=Rd (); if(!n&&!m) Break; for(intI=1; i<=m;i++){ intX=rd (), y=Rd (); Add (x, y), add (y,x); } intCnt=0; intmaxn=-999999; for(intI=0; i<n;i++){ if(!Dfn[i]) {CNT++; Tarjan (i,-1); Num[i]--; } } for(intI=0; i<n;i++) {MAXN=Max (maxn,num[i]); } Write (CNT+MAXN); Puts (""); } return 0;}
Poj2117 Electricity (electric)