http://acm.hdu.edu.cn/showproblem.php?pid=4738
Main topic:
The minimum value of the Bridge (minimum bridge) given the value of n points and M-bars and each edge
It's easy to look at, but there are a lot of details:
1, there will be heavy side
2, if the minimum value is 0, you should output 1
3, M edge may not be able to connect n points, this time no cost.
Caocao ' s Bridges
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3108 Accepted Submission (s): 982
Problem Descriptioncaocao was defeated by Zhuge Liang and Zhou Yu in the Battle of Chibi. But he wouldn ' t give up. Caocao ' s army still is not good at water battles, so he came up with another idea. He built many islands in the Changjiang River, and based on those islands, Caocao ' s Army could easily attack Zhou Yu ' s tro Op. Caocao also built bridges connecting islands. If all islands were connected by bridges, Caocao's army could be deployed very conveniently among those islands. Zhou Yu couldn ' t stand with that, so he wanted to destroy some Caocao ' s bridges so one or more islands would is seperated From the other islands. But Zhou Yu had only one bomb which is left by Zhuge Liang, so he could only destroy one bridge. Zhou Yu must send someone carrying the bomb to destroy the bridge. There might is guards on bridges. The soldier number of the bombing team couldn ' t is less than the guard number of a bridge, or the mission would fail. Least how many soldiers Zhou Yu has To sent to complete the island seperating mission.
Inputthere is no more than test cases.
In each test case:
The first line contains-integers, n and m, meaning that there is N islands and M bridges. All the islands is numbered from 1 to N. (2 <= N <=, 0 < M <= N2)
Next m lines describes M bridges. Each line contains three integers u,v and W, meaning this there is a bridge connecting island U and Island V, and there ar E W guards on the bridge. (u≠v and 0 <= W <= 10,000)
The input ends with N = 0 and M = 0.
Outputfor each test case, print the minimum soldier number Zhou Yu had to send to complete the mission. If Zhou Yu couldn ' t succeed any, print-1 instead.
Sample INPUT3 31 2 72 3 43 1 43 21 2 72 3 40 0
Sample Output-14
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#include<queue>#include<vector>using namespacestd;#defineN 1010#defineINF 0x3f3f3f3fstructnode{intTo,flew,next;} Edge[n*N];intLow[n],dfn[n],time,top,ans,stack[n],belong[n],sum,head[n];voidInn () {memset (Low,0,sizeof(low)); memset (DFN,0,sizeof(DFN)); memset (Stack,0,sizeof(Stack)); Memset (Belong,0,sizeof(belong)); memset (Head,-1,sizeof(head)); time=top=ans=sum=0;}voidAddint from,intTo,intflew) {edge[ans].to=to ; Edge[ans].flew=flew; Edge[ans].next=head[ from]; head[ from]=ans++;}voidTarjin (intUintf) { intv,k=0; Low[u]=dfn[u]=++Time ; Stack[top++]=u; for(inti=head[u];i!=-1; i=Edge[i].next) {v=edge[i].to; if(V==f &&!)k) {k++; Continue; } if(!Dfn[v]) {Tarjin (v,u); Low[u]=min (low[u],low[v]); } ElseLow[u]=min (low[u],dfn[v]); } if(dfn[u]==Low[u]) {Sum++; Do{v=stack[--top]; BELONG[V]=sum; } while(v!=T); }}voidSolveintN) { intk=0; intmin=INF; for(intI=1; i<=n;i++) { if(!Dfn[i]) {k++; Tarjin (i,0); } } if(sum==1) {printf ("-1\n"); return; } if(k>1) {printf ("0\n"); return; } for(intI=1; i<=n;i++) { for(intj=head[i];j!=-1; j=Edge[j].next) { intu=Belong[i]; intv=Belong[edge[j].to]; if(u!=v) {Min=min (Min,edge[j].flew); } } } if(min==0) Min++; printf ("%d\n", Min);}intMain () {intN,m,a,b,c,i; while(SCANF ("%d%d", &n,&m), n+m) {Inn (); for(i=0; i<m;i++) {scanf (" %d%d%d",&a,&b,&c); Add (A,B,C); Add (B,A,C); } solve (n); } return 0;}
Caocao ' s bridges-hdu4738 (tarjin+ Bridge)