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
朱刘算法模板

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define maxn 102
#define maxm 10002
#define inf INT_MAXstruct Node{double x, y;
} ver[maxn];
struct Node2{int u, v;double cost;
} edge[maxm];
double ans;
int pre[maxn], hash[maxn], vis[maxn];
double in[maxn];bool ZL_MST(int root, int nv, int ne)
{ans = 0;int i, u, v, cntnode;while(true){for(i = 0; i < nv; ++i) in[i] = inf;for(i = 0; i < ne; ++i){u = edge[i].u; v = edge[i].v;if(edge[i].cost < in[v] && u != v){pre[v] = u; in[v] = edge[i].cost;}}for(i = 0; i < nv; ++i)if(i != root && in[i] == inf) return false;memset(hash, -1, sizeof(hash));memset(vis, -1, sizeof(vis));in[root] = cntnode = 0;for(i = 0; i < nv; ++i){ans += in[i];v = i;while(vis[v] != i && hash[v] == -1 && v != root){vis[v] = i; v = pre[v];}if(v != root && hash[v] == -1){for(u = pre[v]; u != v; u = pre[u]){hash[u] = cntnode;}hash[v] = cntnode++;}}if(cntnode == 0) break;for(i = 0; i < nv; ++i)if(hash[i] == -1) hash[i] = cntnode++;for(i = 0; i < ne; ++i){v = edge[i].v;edge[i].u = hash[edge[i].u];edge[i].v = hash[edge[i].v];if(edge[i].u != edge[i].v){edge[i].cost -= in[v];}}nv = cntnode;root = hash[root];}return true;
}int main()
{int n, m, a, b, i;double x, y;while(scanf("%d%d", &n, &m) == 2){for(i = 0; i < n; ++i)scanf("%lf%lf", &ver[i].x, &ver[i].y);for(i = 0; i < m; ++i){scanf("%d%d", &a, &b);x = ver[--a].x - ver[--b].x;y = ver[a].y - ver[b].y;edge[i].cost = sqrt(x * x + y * y);edge[i].u = a; edge[i].v = b;}if(ZL_MST(0, n, m)) printf("%.2lf\n", ans);else printf("poor snoopy\n");}return 0;
}

POJ 3164 Command Network相关推荐

  1. POJ 3164 Command Network (最小树形图)

    Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10136   Accepted: 2946 ...

  2. POJ 3164 Command Network(朱刘算法)

    Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 21481   Accepted: 6117 ...

  3. POj 3164 Command Network最小树形图 模板题 朱刘算法

    Command Network After a long lasting war on words, a war on arms finally breaks out between littleke ...

  4. POJ 3164 Command Network (最小树形图)

    [题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...

  5. [POJ 3164]Command Network(最小树形图,朱刘算法)

    文章目录 title solution code title solution 读完翻译后,很明显就是个朱刘算法的板子题 最小树形图,就是给出一个带权有向图 从中指定一个特殊的结点 root 求一棵以 ...

  6. poj 3164 Command Network

    最小树形图,,不熟练啊,写错几个地方无限TLE #include<stdio.h> #include<string.h> #include<math.h> #def ...

  7. Command NetWork(POJ-3164)

    Problem Description After a long lasting war on words, a war on arms finally breaks out between litt ...

  8. POJ 2236 Wireless Network 并查集

    Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS     Memory Limit:6553 ...

  9. Linux command | network

    持续更新中- (1) ip The ip command can show address information, manipulate routing, plus display network ...

最新文章

  1. 什么?终止一个容器竟然用了 10 秒钟,这不能忍!
  2. ssm之九 批量导入excel到数据库
  3. win10共享打印机怎么设置_怎么设置打印机共享?
  4. CSS/DIV网页设计视频教程目录【转】
  5. 本地连接和音量图标显示
  6. NOI数学之提高级:欧拉定理和欧拉函数
  7. nginx下gzip配置参数详解
  8. Linux定制history命令的输出格式
  9. js读取http chunk流_极简 Node.js入门 教程双工流
  10. linux iostat来对linux硬盘IO性能进行了解
  11. nginx命令和配置
  12. Python代码混淆工具,Python源代码保密、加密、混淆
  13. 嵌入式linux ucgui,四、嵌入式之图形界面 (3) uCGui
  14. 认知计算、大数据及人工智能革命
  15. 微信公众号怎么发红包?
  16. APP全栈工程师修炼之路(三)
  17. 解决mybatis-plus分页查询不生效,配置分页拦截器
  18. ThingsBoard使用规则链将设备信息转发至外部mqtt
  19. Oracle:ADG基础知识学习一20230515
  20. 2018年区块链十大发展势头

热门文章

  1. c语言 文件f指针,C语言文件选择题
  2. http java ssl_使用HttpClient通过HTTPS信任所有证书
  3. JAVA 实现FTP功能_Java实现FTP上传下载功能
  4. 使用NavigationUI更新UI组件
  5. 省掉bean自定义spring mvc注解注入json值
  6. Python 通过 pip 安装第三方模块成功,导入该模块失败的解决方法
  7. pandas的to_csv()使用细节和一些参数
  8. yum更换本地源、yum下载和源码包安装
  9. COMBO--组合拳打穿回调地狱~
  10. windows备份0x80070422错误解决方法