All submissions for this problem are available.
The Kingdom of Bytelandia has N cities, numbered from 0 to N−1. There are M bidirectional roads, each of which connects two different cities. The road network in the kingdom is such that people of any city can reach any other city they desired through the road network. This is called having unity in the kingdom. Bytelandia is very famous for its unity. The people are united and familiar with each other. The king of Bytelandia is also very proud of this fact.
But, some people just want to watch the world burn. Dr. Bobo is one of such people. He is very wicked. He doesn't like unity of Bytelandia. He has a chemical missile to spread diseases. He plans to attack one of the cities of Bytelandia.
The king's secret intelligence service became aware of Dr. Bobo's wicked plan and informed the king about it. The king could not catch Dr. Bobo hence he is a genius. So the king planned the rescue mission with his own defense system. The scientists of Bytelandia have made one kind of shields which can protect an entire city from the attack of Dr. Bobo's missile. The shield will not affect the road network, in the sense that a citizen can still travel on the roads connected to a protected city. But the shields are very very expensive to build.
The king also has a team of brilliant doctors, who have already discovered the cure for the disease which the missile will spread. But they can only handle one city at a time. The king has planned his rescue mission as follows:
If a shielded city is attacked by the missile, then no one is harmed. If a city without a shield is attacked, all the roads connected to that city will be closed to prevent the disease from spreading to the other cities. Then, the doctors will begin to cure each citizen of that city and as a precautionary measure, none of those citizens are allowed to leave the city until each and every of them is cured. It will take a very long time to cure an entire city.
Taking a long time to cure an attacked city will affect the road network of the kingdom. The roads which are closed due to the attack can not be used until the affected city is entirely cured. This would have an adverse affect on the kingdom's unity, which the king would never want, especially at the time of crisis because in that case Dr. Bobo would have achieved his evil goal of dividing the people.
The king can make as many shields as he wants but as we know, they are very expensive. So, he would let a city be attacked and then be cured by his doctors rather than pay to plant a shield over a city, as long as it will not affect the unity of the remaining kingdom. That is, city x must be protected by the shield if there exists a pair of cities (except city x) such that people cannot come and go between these cities when the roads connected city x are closed. He doesn't want to make unnecessary shields. He wants you to find the minimum amount of money that is needed to make the shields to prevent Mr. Bobo from succeeding in his evil plan.
First line of input contains an integer T, denoting the number of test cases. Then T test cases follow. First line of each test case contains 3 space-separated integers N, M, and K, denoting number of cities, the number of bidirectional roads, and the cost to make one shield, respectively. Then M lines follow each containing 2 space-separated integers A and B, denoting that there is a road between city A and city B.
For each test case, output the minimum amount of money required to fulfill the king's requirements and protect unity of his kingdom.
- 1 ≤ T ≤ 1500
- 2 ≤ N ≤ 3000
- N−1 ≤ M ≤ N*(N−1)/2)
- 0 ≤ A, B ≤ N−1, A ≠ B
- 1 ≤ K ≤ 1000
- The road network has unity
- No two roads connect the same pair of cities
- The sum of N in one test file does not exceed 3000
Input: 1 7 6 5 0 1 1 2 3 4 2 4 2 6 5 2 Output: 15
In the sample, the cities 1, 2, and 4 must be protected by the shields.
|Tags||april13, dfs, easy, graph, jay_adm|
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions