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. excelize

    // 参考:https://gitee.com/xurime/excelize // github.com/360EntSecGroup-Skylar/excelize

  2. react-router 5.0 的鉴权

    react-router 5.0 的鉴权 当我们使用react-router 控制页面的路由时候,有些页面,是需要登录才能访问,有些不需要登录就可以访问,还有些页面,是根据用户的权限来限制访问的. 如 ...

  3. Java BinarySearch

    Java BinarySearch /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternation ...

  4. 怎样用sql语句复制表table1到表table2的同时复制主键

    原文:怎样用sql语句复制表table1到表table2的同时复制主键 在从table1表复制到table2的时候,我们会用语句: select * into table2 from table1 但 ...

  5. 如何在含有json类型的字段上建立多列索引

    废话不多,直接上图 如 : 表结构如图           那么我想在这三个字段上建立一个唯一索引,目的是为了防止重复插入数据, 1.首先,说明一下 data中的json中,key为 tagID 和 ...

  6. CSS属性margin、padding的区别

    原始状态 不设置margin和padding的状态 margin 设置外边距之后的状态 padding 设置内边距之后的状态 ,注意是撑开,外框高宽由300px变成450px. 说明:本文为原创作品, ...

  7. SAP UI5应用入口App.controller.js是如何被UI5框架加载的?

    首先在UI5应用的manifes.json里,定义了UI5应用的入口视图为App: 调试器里的pending数组的两个元素: 实际上对应了我在App.controller.js里定义的两个依赖: 而a ...

  8. 数据库(sql server 2000)—— 学习笔记1

    一.安装 安装程序一般都是四合一的,SQL Server 2000有四个版本:企业版.标准版.个人版.开发版,每个版本的对系统的要求各不相同. SQL Server 2000各版本 对 操作系统的要求 ...

  9. Python 中文文件统计词频 + 中文词云

    1. 词频统计: import jieba txt = open("threekingdoms3.txt", "r", encoding='utf-8').re ...

  10. 安卓直连SQLSEVER数据库

    1.导入连接SQLSEVER的jar包:可以支持android的SQL驱动(如:jtds-1.2.7.jar) 2.编写连接数据库的工具类 import java.lang.reflect.Field ...