最小树形图poj3164 Command Network

2017年08月09日 10点热度 0人点赞 0条评论
Command Network
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 18628   Accepted: 5340

Description

After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOcean’s kingdoms. A sudden and violent assault by KnuthOcean’s force has 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 that the most urgent point is to enable littenken’s commands to reach every disconnected node in the destroyed network and decides on a plan to build a unidirectional communication network. The
nodes are distributed on a plane. If littleken’s commands are to be able to be delivered directly from a node A to another node B, a wire will have to be built along the straight line segment connecting the two nodes. Since it’s in wartime, not between all
pairs of nodes can wires be built. snoopy wants the plan to require the shortest total length of wires so that the construction can be done very soon.

Input

The input contains several test cases. Each test case starts with a line containing two integer N (N ≤ 100), the number of nodes in the destroyed 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 the nodes. Then follow M lines each containing two integers i and j between
1 and N (inclusive) meaning a wire can be built between node i and node j for unidirectional command delivery from the former to the latter. littleken’s headquarter is always 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 two digits past the decimal point. In the cases that such a network does not exist, just output ‘poor snoopy’.

Sample Input

4 6
0 6
4 6
0 0
7 20
1 2
1 3
2 3
3 4
3 1
3 2
4 3
0 0
1 0
0 1
1 2
1 3
4 1
2 3

Sample Output

31.19

poor snoopy

#include
#include
#include
#include
#include 
using namespace std;
const int M=10005,N=105,inf=1e9;
//最小树形图:选择一些边,使得根节点能够到达图中所有的节点,并使得选出的边的边权和最小 (有向图,所有不可用最小生成树) 
struct Edge{
    int u, v;
	double w;
} edge[M];
int n, m;
int id[N],vis[N],pre[N];
double in[N];
double Directed_MST(int root) {
	//如果ret<0,则不存在最小树形图 
    double ret = 0;
    while(true) {
        for(int i=0;i=0)
		printf("%.2fn",ans);
		else puts("poor snoopy");
	}
	return 0;
} 
未经允许不得转载!最小树形图poj3164 Command Network

update

纸上得来终觉浅, 绝知此事须躬行。