Problem

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

题解:大体意思就是给你一些公交站牌和一些公交路线,定义一个密度,是路线的条数 / 公交站牌的个数。第一行是公交初始的

位置,下面一行对应的是末位置。如果路线一样去重一下就可以了。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
using namespace std;
int vis[550][550];
int a[550],b[550];
int main()
{
int t,n,i,j,m,w;
double ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1; i<=m; i++)
scanf("%d",&a[i]);
for(i=1; i<=m; i++)
scanf("%d",&b[i]);
memset(vis,0,sizeof(vis));
w = 0;
for(i=1; i<=m; i++)
{
if(vis[a[i]][b[i]] == 0)
{
vis[a[i]][b[i]] = 1;
vis[b[i]][a[i]] = 1;
w++;
}
}
// cout<<w<<" "<<n<<endl;
ans = (double)w/(double)n;
printf("%.3lf\n",ans);
}
return 0;
}

Density of Power Network(ZOJ 3708)的更多相关文章

  1. POJ - 1459 Power Network(最大流)(模板)

    1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...

  2. POJ-1459 Power Network(最大流)

    https://vjudge.net/problem/POJ-1459 题解转载自:優YoU http://user.qzone.qq.com/289065406/blog/1299339754 解题 ...

  3. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  4. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  5. [ACM_图论] ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重]

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

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

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

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

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

  8. Power Network (最大流增广路算法模板题)

    Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20754   Accepted: 10872 Description A p ...

  9. 2018.07.06 POJ 1459 Power Network(多源多汇最大流)

    Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...

随机推荐

  1. array_chunk — 将一个数组分割成多个

    说明 array_chunk ( array $array , int $size [, bool $preserve_keys = false ] ) : array 将一个数组分割成多个数组,其中 ...

  2. HTTP协议探究(六):H2帧详解和HTTP优化

    一 复习与目标 1 复习 HTTP1.1存在的问题 HTTP2.0要兼容HTTP1.1 HTTP2.0的重要概念 分帧层 二进制:流 消息 帧 流的状态.优先级和并发 流量控制 服务器推送 首部压缩 ...

  3. sql语句分页多种方式

    sql语句分页多种方式ROW_NUMBER()OVER sql语句分页多种方式ROW_NUMBER()OVER 2009年12月04日 星期五 14:36 方式一 select top @pageSi ...

  4. SublimeText 3 常见快捷键

      ·F12 跳转至预定义 ·F11 全屏模式 ·Ctrl+A 本文全选 ·Ctrl+F 打开底部搜索框,查找关键字. ·Ctrl+D 本文件选中光标选中的单词 ·Ctrl+L 选中光标所在一行 ·C ...

  5. # 机器学习算法总结-第八天(SKlearn中的kmeans/随机森林)

    随机森林 这篇好好看看怎么调参的 我调的最佳参数如下,准确率为0.8428671546929973,细节看上篇文章: alg = RandomForestClassifier(n_estimators ...

  6. burpsuite暴力破解dvwa的登录密码

    前提准备条件: 1.下载安装dvwa,下载链接地址:http://www.dvwa.co.uk/. 2.安装php+mysql环境,我用的是这个软件(phpStudy)下载地址:https://www ...

  7. mysql5.6快速安装及参数详解

    一.所需软件 软件名称 版本 下载地址 当前环境 管理员账号/密码 mysql 5.6 yum安装 centOS6.7系统 zxfly/zxfly 二.安装说明 数据库所在目录 /database/m ...

  8. 集成IDE anaconda

    Anaconda 下载安装完anaconda后,会生成如下工具: 安装Anaconda不需要使用管理员权限.安装完毕后,Anaconda附带一个图形启动器(Anaconda Prompt),可以使用他 ...

  9. Paper Reading:FPN

    FPN 论文:Feature Pyramid Networks for Object Detection 发表时间:2017 发表作者:(Facebook AI Research)Tsung-Yi L ...

  10. 大数据之路week02--day03 Map集合、Collections工具类的用法

    1.Map(掌握) (1)将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值. (2)Map和Collection的区别? A: Map 存储的是键值对形式的元素,键唯一,值可以 ...