{"problem":{"name":"015. Subway System","description":{"content":"You're going to a large city with a complex subway system. You need to find out how many subway lines you will take from the airport to your hotel. Given a list of stations that each subway line stops","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269015"},"statements":[{"statement_type":"Markdown","content":"You're going to a large city with a complex subway system. You need to find out how many subway lines you will take from the airport to your hotel. Given a list of stations that each subway line stops at, print the minimum number of lines you need to take to get from the airport to your hotel.\n\nThe first lines contains one integer _n_, representing the number of different lines in the subway. The next _n_ lines contain an arbitrary number of space-separated strings, each representing the various stations that the subway lines stop at. The airport's station will be _Airport_ in the station list, and the hotel's station will be _Hotel_. There will not be more than 1000 distinct station names.\n\nOutput one positive integer _l_: the minimal number of different subway lines that you should take to reach the hotel station from the airport station.\n\nA note from the creator of the problem (Xavier): This problem is _really_ hard. I created the problem and it took me over an hour to come up with a valid solution. Please only attempt this problem if you know what you're doing.\n\n## Input\n\nThe first lines contains one integer _n_, representing the number of different lines in the subway. The next _n_ lines contain an arbitrary number of space-separated strings, each representing the various stations that the subway lines stop at. The airport's station will be _Airport_ in the station list, and the hotel's station will be _Hotel_. There will not be more than 1000 distinct station names.\n\n## Output\n\nOutput one positive integer _l_: the minimal number of different subway lines that you should take to reach the hotel station from the airport station.\n\n[samples]\n\n## Note\n\nA note from the creator of the problem (Xavier): This problem is _really_ hard. I created the problem and it took me over an hour to come up with a valid solution. Please only attempt this problem if you know what you're doing.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of subway lines.  \nLet $ L_1, L_2, \\dots, L_n \\subseteq S $ be the sets of stations for each line, where $ S $ is the finite set of all station names, and $ \\text{Airport}, \\text{Hotel} \\in S $.  \n\n**Constraints**  \n- $ |S| \\leq 1000 $  \n- $ \\text{Airport} \\in \\bigcup_{i=1}^n L_i $, $ \\text{Hotel} \\in \\bigcup_{i=1}^n L_i $  \n\n**Objective**  \nFind the minimum number of lines $ l \\in \\mathbb{Z}^+ $ such that there exists a sequence of lines $ L_{i_1}, L_{i_2}, \\dots, L_{i_l} $ satisfying:  \n- $ \\text{Airport} \\in L_{i_1} $,  \n- $ \\text{Hotel} \\in L_{i_l} $,  \n- $ L_{i_j} \\cap L_{i_{j+1}} \\neq \\emptyset $ for all $ j \\in \\{1, \\dots, l-1\\} $.  \n\nOutput $ l $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269015","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}