Submit | All submissions | Best solutions | Back to list |
POTHOLE - Potholers |
A team of speleologists organizes a training in the Great Cave of Byte Mountains. During the training each speleologist explores a route from Top Chamber to Bottom Chamber. The speleologists may move down only, i.e. the level of every consecutive chamber on a route should be lower then the previous one. Moreover, each speleologist has to start from Top Chamber through a different corridor and each of them must enter Bottom Chamber using different corridor. The remaining corridors may be traversed by more than one speleologist. How many speleologists can train simultaneously?
Task
Write a program which:
- reads the cave description from the standard input,
- computes the maximal number of speleologists that may train simultaneously,
- writes the result to the standard output.
Input
The number of test cases t is in the first line of input, then t test cases follow separated by an empty line. In the first line of each test case there is one integer n (2<=n<=200), equal to the number of chambers in the cave. The chambers are numbered with integers from 1 to n in descending level order - the chamber of grater number is at the higher level than the chamber of the lower one. (Top Chamber has number 1, and Bottom Chamber has number n). In the following n-1lines (i.e. lines 2,3,...,n) the descriptions of corridors are given. The (i+1)-th line contains numbers of chambers connected by corridors with the i-th chamber. (only chambers with numbers grater then i are mentioned). The first number in a line, m, 0<=m<=(n-i+1), is a number of corridors exiting the chamber being described. Then the following m integers are the numbers of the chambers the corridors are leading to.
Output
Your program should write one integer for each test case. This number should be equal to the maximal number of speleologists able to train simultaneously,
Example
Sample input: 1 12 4 3 4 2 5 1 8 2 9 7 2 6 11 1 8 2 9 10 2 10 11 1 12 2 10 12 1 12 1 12 Sample output: 3
The sample input corresponds to the following cave:
Added by: | Piotr Łowiec |
Date: | 2004-09-13 |
Time limit: | 7s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | 6th Polish Olympiad in Informatics, stage 2 |
hide comments
|
|||||
2016-07-31 17:54:29 Anant Upadhyay
its a max flow problem do it using ford fulkerson algorithm |
|||||
2016-07-30 11:09:15
First on max-flow. Takes time to get going. Worth it! |
|||||
2016-01-20 10:45:40 minhthai
you don't need 7s :) |
|||||
2016-01-15 09:27:51
its a max flow problem do it using ford fulkerson algorithm |
|||||
2015-09-18 12:16:28 Deepanshu Thakur
"Moreover, each speleologist has to start from Top Chamber through a different corridor and each of them must enter Bottom Chamber using different corridor. The remaining corridors may be traversed by more then one speleologist." These lines are the most trickiest part of the problem if you got these words correct then implementation is easy! Solved it in second try! My first Max Flow :) |
|||||
2015-08-08 14:08:15
nice Prob... to start on max flows |
|||||
2014-11-06 09:08:44 kanye west
i'm getting wrong answer omg i was taking the inputs wrong lmao Last edit: 2014-11-06 09:28:30 |
|||||
2014-02-01 19:57:38 akulsareen
My 50th AC and 1st question on flows. Last edit: 2014-02-01 19:58:16 |
|||||
2013-07-03 12:01:29 :p
if there is a direct link from 1st chamber to the nth chamber, then that will be considered as a path or not.?? ans please give some tricky test case..getting WA.! Last edit: 2013-07-03 12:04:33 |
|||||
2013-06-14 10:38:45 Codeblooded
7sseconds? thats too much i think.. |