Minimum Tree chart: In simple terms, to find the minimum G0 of a graph, first find the shortest arc set E0. If E0 does not exist, the minimum tree diagram of Figure G0 does not exist. If it exists and does not contain a forward ring, then E0 is all the edges in the T0. If the E0 exists and contains a forward ring, then the contraction has a direction to the ring as a point u, and the formation of the diagram G1, continue and G1 the smallest tree diagram until the figure GI, if the figure GI No minimum map, then the figure G0 also does not exist the smallest trees, if GI has the smallest of the graph ti. Expand by Layer T0
Specific can refer to this Daniel wrote the process: http://www.cnblogs.com/vongang/archive/2012/07/18/2596851.html (I was reading, the book read for a long while to understand.) )
UVA 11183 Teen Girl Squad
Input:standard Input
Output:standard Output
–3 Spring rolls please.
–msg ' d!!
–oh! My Stomach lining!
Strong Bad
You is part of a group of n teenage girls armed with cellphones. You are some news want to tell everyone in the group. The problem is and no both of the same, and you must communicate using only cellphones. What's worse is this due to excessive usage, your parents has refused to pay your cellphone bills, so you must distribute The news by calling the cheapest possible. You'll call several of your friends, they would call some of their friends, and so on until everyone in the group hears T He news.
Each of are using a different phone service provider, and you know the price of Girl a calling girl B for all possible A and B. Not all of the your friends like each other, and some of them would never call people they don ' t like. Your job is to find the cheapest possible sequence of calls so, the news spreads from your to all n-1 other members of The group.
Input
The first line of input gives the number of cases, N (n<150). N test Cases follow. Each one starts with the lines containing n (0<= n<=1000) and m (0 <= M <= 40,000). Girls is numbered from 0 to n-1 and is girl 0. The next m lines would each contain 3 integers, u, V and W, meaning that a call from girl u to girl v costs W cents (0 < = w <= 1000). No other calls is possible because of grudges, rivalries and because they is, like, lame. The input file size is around KB.
Output
For each test case, output one line containing ' case #x: ' followed by the cost of the cheapest method of distributing the News. If There is no solution, print "possums!" instead.
Sample input Output for sample input
4
2
1
0 1 10
2
1
1 0 10
4
4
0 1 10
0 2 10
1 3 20
2 3 30
4
4
0 1 10
1 2 20
2 0 30
2 3 100
Case #1:10
Case #2: possums!
Case #3:40
Case #4:130
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#include <cmath>Using namespace Std;constintmaxn=1010; constintINF =0x3f3f3f3f; constintMAXM =40010; struct edge{intU,v,cost;} EDGE[MAXM];intPRE[MAXN],ID[MAXN],VIS[MAXN],IN[MAXN];intZhuliu (intRootintNint m, Edge edge[]) {intU,v;intres=0; while(1) { for(intI=0; i<n;i++) In[i]=inf; for(intI=0;i<m; i++)if(edge[i].u!=edge[i].v && Edge[i].cost < IN[EDGE[I].V]) {pre[edge[i].v]=edge[i].u; IN[EDGE[I].V]=edge[i].cost; } for(intI=0; i<n;i++)if(I!=root&&in[i]==inf)return-1;inttn=0; memset (id,-1, sizeof (ID)); memset (vis,-1, sizeof (VIS)); in[root]=0; for(intI=0; i<n;i++) {res+=in[i]; V=i; while(vis[v]!=i&&id[v]==-1&&v!=root) {vis[v]=i; V=PRE[V]; }if(V!=root && id[v]==-1) { for(intU=pre[v];u!=v;u=pre[u]) Id[u]=tn; id[v]=tn++; } }if(tn==0) Break; for(intI=0; i<n;i++)if(id[i]==-1) id[i]=tn++; for(intI=0;i<m;) {v=edge[i].v; EDGE[I].U=ID[EDGE[I].U]; EDGE[I].V=ID[EDGE[I].V];if(EDGE[I].U!=EDGE[I].V) edge[i++].cost-=in[v];ElseSwap (edge[i],edge[--m]); } n=tn; Root=id[root]; }returnRes;}intG[MAXN][MAXN];intMain () {intTintNm;intCase=0; scanf"%d", &t); while(t--) {case++; scanf"%d %d",&n,&m); for(intI=0; i<n;i++) for(intj=0; j<n;j++) G[i][j]=inf;intU,v, cost; for(intI=1; i<=m; i++) {scanf (" %d%d%d", &u,&v,&cost);if(U==V)Continue;//printf("%lf\ n", Dis (p[u],p[v])); G[u][v]=min (G[u][v],cost); }intL=0; for(intI=0; i<n;i++) for(intj=0; j<n;j++)if(G[i][j]<inf) {edge[l].u=i; Edge[l].v=j; EDGE[L++].COST=G[I][J]; }intAns=zhuliu (0, N,l,edge);printf("Case #%d:", case);if(ans==-1)printf("possums!\n");Else printf("%d\ n", ans); }return 0;} POJ3164Command networktime Limit: +MS Memory Limit:131072Ktotal Submissions:14340Accepted:4118Descriptionafter a long lasting war on words, a war in arms finally breaks out between Littleken 's andKnuthocean 'sKingdoms. A Sudden andViolent assault by Knuthocean 'sForce have rendered a total failure of Littleken 'sCommand network. A Provisional network must be built immediately. Littleken orders Snoopy to take charge of the project. With the situation studied to every detail, Snoopy believes, and the most urgent point are to enable Littenken 'sCommands to reach every disconnected node in the destroyed network andDecides on a plan to build a unidirectional communication network. The nodes is distributed on a plane. If Littleken 'sCommands is to being able to being delivered directly from a node A to another node B and a wire would has to be built along the s Traight line segment connecting the nodes. Since it 'sIn wartime, notBetween all pairs of nodes can wires be built. Snoopy wants the plan torequireThe shortest totallengthof wires So, the construction can is done very soon. Inputthe input contains several test cases. Each test case is starts with a line containing the integer N (n≤ -), the number of nodes in the destroyed network, andM (m≤104), the number of pairs of nodes between which a wire can be built. TheNextN lines eachContain an ordered pair XI andYi, giving the Cartesian coordinates of the nodes. Then follow M lines eachContaining II integers i andJ between1 andN (inclusive) meaning a wire can be built between node I andNode J forUnidirectional command delivery from the former to the latter. Littleken 'sHeadquarter is all located at node1. Process to end of file. Outputfor eachTest case, output exactly one line containing the shortest totallengthof wires to digits past the decimal point. In the cases, that such a network does notexist, just output ' poor Snoopy '. Sample Input4 60 64 60 07 -1 21 32 33 43 13 24 30 01 00 11 21 34 12 3Sample Output31.19Poor Snoopy
The previous question will be very good to think about this problem, code yourself practice it!
POJ 3164Command Network && UVA 11183 Teen Girl Squad minimum tree diagram