Starting from planet 0, conquer the fewest planets that threaten planet 1, preferring the choice that threatens the most planets, and output both counts.
Medium6Shortest pathBFSBrute forceNo attempts yetTime limit5sMemory limit512 MBA.I. War is a real-time strategy game made by Arcen Games. This problem was inspired by that game, but you do not need to have played it.
You are fighting an artificial intelligence for the future of the galaxy. To defeat the A.I. you have to threaten its home planet. Some planets are connected to each other by wormholes, and a planet may be connected to any number of other planets.
You start out owning only your own home planet. Each turn you may conquer any planet you threaten. You threaten a planet if you do not own it and it is connected by a wormhole to one of the planets you own. Once you conquer a planet, you own it. As soon as you threaten the A.I.'s home planet, you may not conquer any more planets.
At tactical school you learned two facts about the A.I.
Those two facts give you a strategy.
Given the planets and the wormholes, find how many planets you conquer and how many you threaten at the end when you follow this strategy.
The first line contains the number of test cases T. T test cases follow. The first line of each test case contains two space separated integers, the number of planets P and the number of wormholes W. Your home planet is planet 0 and the A.I.'s home planet is planet 1.
The second line of each test case contains W space separated pairs of comma separated integers xi,yi. Each pair means one two way wormhole connecting planet xi and planet yi.
For each test case print one line in the format Case #x: c t, where x is the test case number starting from 1, c is the number of planets you conquer under this strategy, and t is the number of planets you threaten at the end. The A.I.'s home planet counts toward t.
The sample input holds four cases.
In the first case there are 2 planets and one wormhole joins planet 0 and planet 1. You conquer nothing and already threaten the A.I.'s home planet.
In the third case one conquest is enough to threaten the A.I.'s home planet. You end up threatening 2 planets, and one planet is left that no wormhole touches.
In the fourth case you threaten the A.I.'s home planet after conquering planets 4 and 5. You end up threatening planets 6, 2, 3, and planet 1, the A.I.'s home planet.