The vast power system is the most complicated man-made system and the greatest engineering innovation in the 20th century. The following diagram shows a typical 14 bus power system. In real world, the power system may contains hundreds of buses and thousands of transmission lines.

Network topology analysis had long been a hot topic in the research of power system. And network density is one key index representing the robustness of power system. And you are asked to implement a procedure to calculate the network density of power system.

The network density is defined as the ratio between number of transmission lines and the number of buses. Please note that if two or more transmission lines connecting the same pair of buses, only one would be counted in the topology analysis.

Input

The first line contains a single integer T (T ≤ 1000), indicating there are T cases in total.

Each case begins with two integers N and M (2 ≤ NM ≤ 500) in the first line, representing the number of buses and the number of transmission lines in the power system. Each Bus would be numbered from 1 to N.

The second line contains the list of start bus number of the transmission lines, separated by spaces.

The third line contains the list of corresponding end bus number of the transmission lines, separated by spaces. The end bus number of the transmission lines would not be the same as the start bus number.

Output

Output the network density of the power system in a single line, as defined in above. The answer should round to 3 digits after decimal point.

Sample Input

3
3 2
1 2
2 3
2 2
1 2
2 1
14 20
2 5 3 4 5 4 5 7 9 6 11 12 13 8 9 10 14 11 13 13
1 1 2 2 2 3 4 4 4 5 6 6 6 7 7 9 9 10 12 14

Sample Output

0.667
0.500
1.429

Author: WANG, Yelei
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

题目大意:每个样例第一行是公交车的数目与路线的数目,第二行是公交车起点,第三行是终点,从a->b与b->a是同一条路线,计算总路线与车辆数目的比值

解题思路:水题,不解释。

 #include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<set>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int N,M;
cin>>N>>M;
int start[],end[];
for(int i=;i<M;i++)
cin>>start[i];
for(int i=;i<M;i++)
cin>>end[i]; int curM=M;
for(int i=;i<M-;i++){
for(int j=i+;j<M;j++){
if((start[i]==start[j] && end[i]==end[j])
||(start[i]==end[j] && end[i]==start[j])){
curM--;
break;
}
}
} printf("%.3lf\n",curM/(1.0*N));
}return ; }

[ACM_图论] ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重]的更多相关文章

  1. zoj 3708 Density of Power Network

    /*看英文和图我头都大了,不过很简单的.*/ #include<string.h> #include<stdio.h> ][],q[],w[]; int main(int ar ...

  2. ZOJ Problem Set - 3708 Density of Power Network

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3708 #include <stdio.h> #include ...

  3. Density of Power Network(ZOJ 3708)

    Problem The vast power system is the most complicated man-made system and the greatest engineering i ...

  4. ZOJ3708:Density of Power Network

    The vast power system is the most complicated man-made system and the greatest engineering innovatio ...

  5. POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)

    POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...

  6. poj1459 Power Network (多源多汇最大流)

    Description A power network consists of nodes (power stations, consumers and dispatchers) connected ...

  7. Power Network(网络流最大流 & dinic算法 + 优化)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24019   Accepted: 12540 D ...

  8. Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏

    Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...

  9. POJ1459 Power Network(网络最大流)

                                         Power Network Time Limit: 2000MS   Memory Limit: 32768K Total S ...

随机推荐

  1. Autofac 的属性注入方式

    介绍 该篇文章通过一个简单的 ASP.NET MVC 项目进行介绍如何使用 autofac 及 autofac 的 MVC 模块进行依赖注入.注入方式通过构造函数.在编写 aufofac 的依赖注入代 ...

  2. 记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject

    原因:Jetty会导致这个问题,Tomcat可以正常启动   一.异常产生现象 使用json-lib转换实体类/字符串,跑单元测试没问题,但是启动jetty后调用JSONArray.fromObjec ...

  3. Linux内核模块简介

    一. 摘要 这篇文章主要介绍了Linux内核模块的相关概念,以及简单的模块开发过程.主要从模块开发中的常用指令.内核模块程序的结构.模块使用计数以及模块的编译等角度对内核模块进行介绍.在Linux系统 ...

  4. 在Eclipse上操作Hive-0.13.1-JDBC端口

    fesh个人实践,欢迎经验交流!本文Blog地址:http://www.cnblogs.com/fesh/p/3877740.html 完成<在Hadoop-2.2.0集群上安装 Hive-0. ...

  5. FIFO跨时钟域读写

    今天面试,要走时问了我一个问题:如果两个时钟一个时钟慢一个时钟快,来读写FIFO,其中读出的数据是 连续的一段一段的. 图1 图1为写时序控制,可以看出数据是两个时钟周期的长度,当然实际中可以是任意周 ...

  6. hdu 1573 X问题 (非互质的中国剩余定理)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. centos添加开机启动项目

    centOS 配置开机自启动两种方式: 1.vi /etc/rc.d/rc.local 在此文件中加入启动的脚本 2.chkconfig 增加自己的脚本  --add --list --del 步骤: ...

  8. expdp小记

    一.10.2.0.5要求expdp导出a用户b表空间下的数据. expdp \'/ as sysdba\' directory=mydir dumpfile=1.dmp schemas=a exclu ...

  9. jquery load 加载改造,只加载body

    背景: 项目中大量用到了jquery和easyui组件,原生load经常出现主页面异常,原因是组件被重复初始化.也考虑过用iframe,但是在实际项目中的效果,最终取消了iframe方案,也尝试了其他 ...

  10. 数据库开发及ADO.NET

    大部分数据库都需要数据库服务器才能运行. Catalog(分类)又叫做数据库DataBase Table(表)不同类型的东西放到不同的区域中,将这种区域叫做表. 列(Column)字段Field 主键 ...