Zoj 3708 density of Power Network

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 dimo-shows a typical 14 bus power system. in real world, the power system may contain 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 buckets. please note that if two or more transmission lines connecting the same pair of buses, only one wocould be counted in the topology analysis.

Input

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

Each case begins with two integersNAndM(2 ≤N,
M
≤ 500) In the first line, representing the number of buckets and the number of transmission lines in the power system. Each bus wocould be numbered from 1
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 wocould 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 shound to 3 digits after decimal point.

Sample Input
 
33 21 22 32 21 22 114 202 5 3 4 5 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

I was scared by the question. It is actually a super question.

That is, the number of power lines except the number of power stations. However, the two power stations have only one wire.


 
# Include <stdio. h> # include <string. h> int s [550], E [550], State [550] [550]; // s records the start of the total power station. E. Record the end Of the total power station // state record whether the two power stations have existing wires. Because the two power stations have only one int main () {int T, M, N, I; double sum; scanf ("% d", & T ); while (t --) {memset (State, 0, sizeof State); scanf ("% d", & N, & M); sum = 0; for (I = 1; I <= m; I ++) scanf ("% d", & S [I]); for (I = 1; I <= m; I ++) scanf ("% d", & E [I]); for (I = 1; I <= m; I ++) {If (! State [s [I] [E [I]) {sum ++; State [s [I] [E [I] = 1; state [E [I] [s [I] = 1 ;}} printf ("%. 3lf \ n ", sum/n); // calculate the wire density} return 0 ;}

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.