TopCoder problem "FlightConnections" used in SRM 10 (Division I Level Three , Division II Level Three)



Problem Statement

    
Class Name: FlightConnections
Method Name: getMinimum
Parameters: String[], String, String
Returns: int

Implement a class FlightConnections, which contains a method getMinimum.
getMinimum takes a String[] representing a list of available flights, a String
representing the departure city, and a String representing the intended
destination.  It returns the minimum number of flights needed to arrive from
the departure city to the destination city.

Note:
*If the departure city and the intended destination are the same, no flights
are needed, so return 0.  
*If there is no possible connection from the departure city to the destination
city, return 0.
*If either the departure or arrival city is not mentioned in the String[],
return 0.
*City names are case sensitive.
*Departure and arrival times don't play any roll.
*Flights are directional.  That is if there is a flight from city A to city B
there isn't necessarily a flight in the reverse direction.
*Duplications in the String[] are ignored.
String[] elements are of the form:
"FROM, TO" (There is a comma followed by exactly one space between FROM and TO).
representing a flight from FROM to TO.  FROM and TO contain letters and dashes
('-'). 

Here is the method signature:
int getMinimum(String[] flights, String strDeparture, String strDestination);
Be sure your method is public.

* flights will be a String[] of the form above.  It has between 1 and 20
elements. Each element is at most 50 characters long.
* strDeparture and strDestination will be Strings consisting only of characters
from the set A-Z, a-z, and "-" (dash).

* TopCoder will check the validity of the inputs.
Examples(quotes are for clarity, but not included in the Strings):
   Flights: ["T, B", "O, F", "D, Y", "F, K", "K, C", "V, N", "B, O"]
   Departure From: T
   Destination: C
   Minimum flights: 5 (T to B; B to O; O to F; F to K; K to C)

   Flights: ["Y, C", "O, F", "Y, O", "M, O", "C, K", "O, K", "K, S", "K, M"]
   Departure From: Y
   Destination: Y
Minimum flights: 0 (the intended destination is the same as the departure
city)

   Flights: ["Here, Ba", "Ba, Ya", "Fa, Qa"]
   Departure From: Here
   Destination: Qa
   Minimum flights: 0 (no possible way to get from Here to Qa)
 

Definition

    
Class:FlightConnections
Method:getMinimum
Parameters:String[], String, String
Returns:int
Method signature:int getMinimum(String[] param0, String param1, String param2)
(be sure your method is public)
    

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=93

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=3009&pm=93

Writer:

Unknown

Testers:

Problem categories: