Poj 3164 Command Network "minimum tree diagram"

Source: Internet
Author: User

Command Network
Time Limit: 1000MS Memory Limit: 131072K
Total Submissions: 15914 Accepted: 4583

Description

After a long lasting war in words, a war on arms finally breaks out between Littleken ' s and Knuthocean ' s kingdoms. A sudden and violent assault by Knuthocean's force have rendered a total failure of Littleken ' s command 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 was to enable Littenken ' s commands t o Reach every disconnected node in the destroyed network and decides on a plan to build a unidirectional communication net Work. The nodes is distributed on a plane. If Littleken ' s commands is to being able to being delivered directly from a node-to-another node B, a wire would has to be BU Ilt along the straight line segment connecting the nodes. Since It's in wartime, not between all pairs of the nodes can wires be built. Snoopy wants the plan to require, the shortest total, length of wires so, the construction can is done very soon.

Input

The input contains several test cases. Each test case is starts with a line containing the integer n (n ≤100) and the number of nodes in the destroy Ed Network, and m (m ≤104), the number of pairs of nodes between which a wire can be built. The next N lines each contain an ordered pair XI and Yi, giving the Cartesian coordinates of TH E nodes. Then follow Mlines each containing II integers i and J between 1 and N (inclusive) Meaning a wire can is built between node I and node J for unidirectional command delivery from the F Ormer to the latter. Littleken ' s headquarter is all located at Node 1. Process to end of file.

Output

For each test case, output exactly one line containing the shortest total length of wires to the digits past the decimal p Oint. In the cases this such a network does not exist, just output ' poor snoopy .

Sample Input

4 60 64 60 07 201 21 32 33 43 13 24 30 01 00 11 21 34 12 3

Sample Output

31.19poor Snoopy

Source

POJ monthly--2006.12.31, Galaxy

Test instructions

Give a direction graph, give the coordinates of n vertices, and each edge connected vertex, specify a starting point, find a scheme, so that from this point to all other points of the path of the weight and minimum, the minimum weight value


Exercises

The legend of the smallest tree diagram, the equivalent of undirected graph of the smallest generation of trees, but a lot of things to consider, after all, the connectivity of the graph is more complex to judge ....

Not too will this algorithm, probably see the point, is understanding, the Great God blog point here ...


Can't find much relevant content on the net, want to try the template is difficult ....


/*http://blog.csdn.net/liuke19950717*/#include <cstdio> #include <cmath> #include <cstring># include<algorithm>using namespace Std;const int inf=0x3f3f3f3f;const int maxn=1005;struct point{double x, y;} P[maxn];struct Node{int u,v;double Len; Edge[maxn*maxn];int PRE[MAXN],ID[MAXN],VIS[MAXN];d ouble in[maxn];d ouble dis (point a,point b) {return sqrt ((a.x-b.x) * ( a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Double dir_mst (int root,int n,int m) {double Ans=0;while (1) {///first find the smallest incoming edge of all points/*memset (in,inf,sizeof (in));//This will be an error! */for (int i=0;i<n;++i) {in[i]=inf;} for (int i=0;i<m;++i) {int u=edge[i].u,v=edge[i].v;if (edge[i].len<in[v]&&u!=v) {pre[v]=u;in[v]=edge[i ].len;}} for (int i=0;i<n;++i) {if (i==root) {continue;} if (in[i]==inf) {return-1;//If a point is zero, the}}//must not be found to check whether these edges constitute a ring memset (id,-1,sizeof (ID)); memset (vis,-1,sizeof (Vis)); in[ Root]=0;int cnt=0;for (int i=0;i<n;++i)//Mark Ring {ans+=in[i];int V=i;while (vis[v]!=i&&id[v]==-1&&v!= Root) {vis[v]=i;v=pre[v];} if (v!=root&&id[v]==-1)//indent {for (int u=pre[v];u!=v;u=pre[u]) {id[u]=cnt;} id[v]=cnt++;}} if (cnt==0) {break;//no ring}for (int i=0;i<n;++i) {if (id[i]==-1) {id[i]=cnt++;}} Create a new diagram for (int i=0;i<m;++i) {int u=edge[i].u,v=edge[i].v;edge[i].u=id[u];edge[i].v=id[v];if (Id[u]!=id[v]) {edge[ I].LEN-=IN[V];}} N=cnt;root=id[root];} return ans;} int main () {int n,m;while (~scanf ("%d%d", &n,&m)) {for (int i=0;i<n;++i) {scanf ("%lf%lf", &p[i].x,&p[ I].Y);} for (int i=0;i<m;++i) {scanf ("%d%d", &AMP;EDGE[I].U,&AMP;EDGE[I].V);--edge[i].u;--edge[i].v;if (edge[i].u!=edge[ I].V) {Edge[i].len=dis (p[edge[i].u],p[edge[i].v]);} Else{edge[i].len=inf;}} Double Ans=dir_mst (0,n,m); if (ans==-1) {printf ("poor snoopy\n");} else{printf ("%.2f\n", ans);}} return 0;}


Poj 3164 Command Network "minimum tree diagram"

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.