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. MySQL CMake参数说明手册

    MySQL自5.5版本以后,就开始使用CMake编译工具了,因此,你在安装源文件中找不到configure文件是正常的.很多人下到了新版的MySQL,因为找不到configure文件,不知道该怎么继续 ...

  2. NGUI ScrollView总结

    1顶级父类加boxCollider和UIDragScrollView脚本保证在item拖走后也能通过拖拽剩余区域的方式操作. 2下一级添加UIPanel在Clipping设定区域,注意如果设定soft ...

  3. 使用阿里Docker镜像加速器加速

    在阿里开发者平台注册开发者账号 https://dev.aliyun.com/search.html 注册之后可以访问Docker镜像服务 https://cr.console.aliyun.com/ ...

  4. jquery 删除数组元素

    expertsId.splice($.inArray(thisID.split('&')[0],expertsId),1); 1. expertsId数组名2. thisID.split('& ...

  5. C. Santa Claus and Robot 思考题

    http://codeforces.com/contest/752/problem/C 这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列. 对于有若干条最短路径走到第i ...

  6. plink:将bed文件转化为ped,map文件

    用--recode命令,--out表示转化的文件的名字,本例已经命名为“filter” /plink-1.07-x86_64/plink --bfile filter --recode --out f ...

  7. (转)SqlBulkCopy批量复制数据

    在.Net1.1中无论是对于批量插入整个DataTable中的所有数据到数据库中,还是进行不同数据源之间的迁移,都不是很方便.而 在.Net2.0中,SQLClient命名空间下增加了几个新类帮助我们 ...

  8. javascript 高级程序设计 十二

    1.组合使用原型模式和构造函数模式: 由于原型模式创建对象也有它的局限性------有智慧的人就把原型模式和构造函数模式进行了组合. function Person(name, age, job){/ ...

  9. php基础-转义字符

    1.php是弱类型语言,定义变量时无需要定义 2.标量类型:整形.浮点型.字符串类型.布尔型 复合类型:数组.对象 其它类型:资源类型(resource如数据库连接,打开文件句柄,资源在不需要时都要释 ...

  10. Daily Scrum 12.5

    今日完成任务: 对webservice进行学习,并将部分接口封装到webservice,没做完,明天继续.以便安卓组能够调用webservice的接口. 修复了大部分数据库改动后导致的异常,网站已可以 ...