eolymp
bolt
Try our new interface for solving problems
Məsələlər

More Fun in Bicol

More Fun in Bicol

The Bicol region (Region 5) is composed of six provinces. They are Albay, Camarines Norte, Camarines Sur, Sorsogon and the island-provinces of Catanduanes and Masbate. The cities in the Bicol region are Iriga City, Legazpi City, Ligao City, Masbate City, Naga City, Sorsogon City, and Tabaco City. \includegraphics{https://static.e-olymp.com/content/1a/1a8535855594de709d491ccbb29171e526813eff.jpg} \textit{\textbf{Figure 1}}: Map of Bicol Region (Location are for illustration purposes only) Most of the contestants could not wait to complete the competition and had begun planning on exploring the region. They had started asking where certain places were and are in the process of listing down the relative location between places. \InputFile The input contains several test cases. Each test case contains two data sets. The first data set describes the relative location of the first place to the second, and the second data set contains queries on the relative location of the first place to the second. For example Data set 1 Data set 2 Thus in the above example, there are \textbf{5} and \textbf{4} entries in data set \textbf{1} and \textbf{2} respectively. Data set 1 is composed of a set of city pair values and a relative location. Each entry indicates that relative location of place \textbf{1} to \textbf{2}. For instance, the entry (Naga City, City of Iriga, Northwest) means that the Naga City is northwest of City of Iriga. However, the data set will not have reverse relationship entry. For instance, (City of Iriga, Naga City, Southeast). The data starts with two integers, \textbf{m} and \textbf{n}, representing the number of entries in data sets \textbf{1} and \textbf{2} respectively, where (\textbf{1} ≤ \textbf{m} ≤ \textbf{100}) and (\textbf{1} ≤ \textbf{n} ≤ \textbf{50}). This is followed by m entries of position description and n entries of queries. The data entries are comma delimited and may contain mixed cases. The allowed relative positions are north, south, east, west, northeast, northwest, southeast and southwest. It is assumed that the each individual relative position has a value of \textbf{1}. These are \textbf{1} north, \textbf{1} south, \textbf{1} east, \textbf{1} west, \textbf{1} north and \textbf{1} east, \textbf{1} north and \textbf{1} west, \textbf{1} south and \textbf{1} east, and \textbf{1} south and \textbf{1} west respectively. Thus, the distance from Masbate City to Naga City is the same as Sorsogon City to Legazpi City. There is a blank line between test cases and the last test case is followed by a single integer zero. \OutputFile For each test case, output the relative position of the places being queried. The system will output "\textbf{Relative location cannot be determined}" if there is insufficient information; however the system should attempt to use all necessary information to obtain a result.
Zaman məhdudiyyəti 5 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
5 4
Naga City,City of Iriga,Northwest
Masbate City,Naga City,Southeast
Tabaco City,City of Ligao,Northeast
Sorsogon City,Legazpi City,Southeast
City of Ligao,Legazpi City,West
Naga City,City of Iriga
City of Iriga, Naga City
Sorsogon City, Naga City
Sorsogon City, City of Ligao

0
Çıxış verilənləri #1
Case 1
Naga City is northwest of City of Iriga
City of Iriga is southeast of Naga City
Relative location cannot be determined
Sorsogon City is southeast of City of Ligao
Mənbə ACM ICM Philippines Multi-Provincial Programming Contest 2013