Woburn Challenge 2017-18 Finals Round - Senior Division
Great military strategists know that a battle occurs beyond just the front lines. To prepare for the upcoming war against the Party of Extraterrestrial Gangsters, the cows and monkeys will need to have an impeccable communications network for relaying important military commands behind the scenes. To this end, chief scientist of the bovine army Guglielmoo Marcowni has developed a powerful new technology — the radio! While his radio technology is very impressive, it sometimes suffers from the issue of poor signals. To quantify the smoothness of a network, Marcowni has developed a measure of signal quality known as Communication Compatibility. A large Communication Compatibility score between radios suggests a great connection, a negative score suggests a very poor connection, and a score of zero suggests a so-so connection.
The cow-monkey army is made up of
Bo Vine and the Head-Monkey want to create a communication network out
of one or more of the
Bo Vine and the Head-Monkey want to make their network as smooth as
possible. Naturally, their choice will be based on the Communication
Compatibility scores of the channels they choose to implement. To help
them quantify the overall smoothness of the network, Marcowni has
defined a benchmark known as the Cumulative Communication
Compatibility (CCC) score. The CCC score of the network is defined to
be the sum of the Communication Compatibilities of all communication
channels that make up the network. Please help Marcowni determine the
maximum possible CCC score that a valid network connecting all Impossible
instead.
Subtasks
In test cases worth
In test cases worth another
In test cases worth another
Input Specification
The first line of input consists of two space-separated integers,
Output Specification
Output a single line consisting of either a single integer, the maximum
possible CCC score of any valid network, or the string Impossible
if
no valid network exists.
Sample Input 1
4 5
1 2 -1
2 3 -5
3 4 -3
4 1 -2
4 2 -3
Sample Output 1
-6
Sample Input 2
5 4
1 2 5
2 3 2
3 1 -1
4 5 0
Sample Output 2
Impossible
Sample Explanation
In the first example, one possible optimal network is by implementing
the first, third, and fourth communication channels. The CCC score of
such a network is
In the second example, there is no way to allow any of the first three combat units to communicate with any of the last two units, so it is impossible to build a valid network.
Comments