CF1204C Anna, Svyatoslav and Maps

Description

The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $ n $ vertexes and a path in it (that path is not necessary simple) given by a sequence $ p_1, p_2, \ldots, p_m $ of $ m $ vertexes; for each $ 1 \leq i < m $ there is an arc from $ p_i $ to $ p_{i+1} $ . Define the sequence $ v_1, v_2, \ldots, v_k $ of $ k $ vertexes as good, if $ v $ is a subsequence of $ p $ , $ v_1 = p_1 $ , $ v_k = p_m $ , and $ p $ is one of the shortest paths passing through the vertexes $ v_1 $ , $ \ldots $ , $ v_k $ in that order. A sequence $ a $ is a subsequence of a sequence $ b $ if $ a $ can be obtained from $ b $ by deletion of several (possibly, zero or all) elements. It is obvious that the sequence $ p $ is good but your task is to find the shortest good subsequence. If there are multiple shortest good subsequences, output any of them.

Input Format

N/A

Output Format

N/A

Explanation/Hint

Below you can see the graph from the first example: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1204C/71cf125b3567a608d3e838a04ba123f82afa0825.png) The given path is passing through vertexes $ 1 $ , $ 2 $ , $ 3 $ , $ 4 $ . The sequence $ 1-2-4 $ is good because it is the subsequence of the given path, its first and the last elements are equal to the first and the last elements of the given path respectively, and the shortest path passing through vertexes $ 1 $ , $ 2 $ and $ 4 $ in that order is $ 1-2-3-4 $ . Note that subsequences $ 1-4 $ and $ 1-3-4 $ aren't good because in both cases the shortest path passing through the vertexes of these sequences is $ 1-3-4 $ . In the third example, the graph is full so any sequence of vertexes in which any two consecutive elements are distinct defines a path consisting of the same number of vertexes. In the fourth example, the paths $ 1-2-4 $ and $ 1-3-4 $ are the shortest paths passing through the vertexes $ 1 $ and $ 4 $ .