The cask of amontillado P31675


Statement
 

pdf   zip

The thousand injuries of Fortunato I had borne as I best could; but when he ventured upon insult, I vowed revenge… We continued our route in search of the amontillado. We passed through a range of low arches, descended, passed on, and descending again, arrived at a deep crypt…
I forced the last stone into its position; I plastered it up… In pace requiescat!

With the excuse of sampling a cask of amontillado, Montressor has guided poor drunken Fortunato through the catacombs under Montressor’s palace. There, in a very remote crypt, Montressor has immured Fortunato inside a hidden niche. Now Montressor wants to return to the chamber where they started their route, but he has forgotten the way to get there. Fortunatoly, Montressor has a map of the catacombs, which shows all the chambers and their direct connections. (Note that some steps are so difficult that it may be possible to pass from one chamber uu to another vv, but not directly back from vv to uu.) The map also shows which chambers contain amontillado.

Montressor and Fortunato went from a starting chamber xx to another chamber yy where they are now. Ironically, Montressor knows that there is no path from xx to any chamber with amontillado. Montressor also knows that it is possible to go from yy back to xx. However, he cannot identify which is xx nor which is yy in the map. Please help him by computing the number of possible combinations for xx and yy that are consistent with all this information.

Input

Input consists of several cases. Each one begins with the number of chambers nn, a number cc, and cc different chambers that contain amontillado. Follows a number mm, and mm different pairs uvu \enspace v (with uvu \ne v) denoting that there is a direct connection from uu to vv. Assume 0n100000 \le n \le 10000, 0cn0 \le c \le n, and 0m10n0 \le m \le 10n. The chambers are numbered from 0 to n1n - 1.

Output

For every case, print its number, followed by the number of combinations for xx and yy that are consistent with Montressor’s knowledge.

Public test cases
  • Input

    5 1  2
    6    0 3  3 0  2 3  1 2  1 4  4 1
    8 0
    7    1 3  0 3  0 1  5 0  3 0  7 6  0 4
    

    Output

    Case #1: 2
    Case #2: 6
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++