ZOJ 3708 Density of Power Network (water problem)

Source: Internet
Author: User

Density of Power Network Time limit: 2 Seconds Memory Limit: 65536 KB

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-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 the power system. And network density is one key index representing the robustness of power system. And you is asked to implement a procedure to calculate the network density of the power system.

The network density is defined as the ratio between number of transmission lines and the number of buses. Please note if you or transmission lines connecting the same pair of buses, only one would being counted in the top Ology analysis.

Input

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

Each case begins with integers n and M (2≤ n, m ≤500) in the first line, Represe Nting the number of buses and the number of transmission lines in the power system. Each Bus would is 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 being 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
33 21 22 32 21 22 114 202 5 3 4 5 4 5 7 9 6 11 12 13 8 9 10 14 11 13 131 1 2 2 2 3 4 4 4 5 6 6 6 7 7 9 9 10 12 14
Sample Output
0.6670.5001.429

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

Find the number of connected segments of two points to the point ratio, 1->2 2->1 as the same line segment

1#include <cstdio>2#include <cstring>3#include <stdlib.h>4#include <algorithm>5 using namespacestd;6 Const intmaxn= +;7 intS[MAXN][MAXN],STAR[MAXN],EN[MAXN];8 intMain ()9 {Ten     //freopen ("In.txt", "R", stdin); One     intkase,n,m; Ascanf"%d",&Kase); -      while(kase--) -     { thememset (s),0,sizeof(s)); -scanf"%d%d",&n,&m); -          for(intI=0; i<m;i++) -scanf"%d",&star[i]); +          for(intI=0; i<m;i++) -scanf"%d",&en[i]); +         DoubleCnt=0; A          for(intI=0; i<m;i++) at         { -             if(!S[star[i]][en[i]]) -cnt++; -s[star[i]][en[i]]=s[en[i]][star[i]]=1; -         } -printf"%.3lf\n",(Double) cnt/n); in     } -     return 0; to}
View Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.