链接:
https://ac.nowcoder.com/acm/contest/33192/L
来源:牛客网
Grammy has a simple connected undirected graph. Each of the edges has a value written on it. Please choose a simple cycle for her such that the values written on the cycle has maximum range.
The range of a cycle is the difference between the maximum value and the minimum value written on it.
A cycle
i1−e1−i2−e2−⋯−ik−ek−i1i_1 - e_1 - i_2 - e_2 - \cdots - i_k - e_k - i_1i1−e1−i2−e2−⋯−ik−ek−i1 (
eje_jej is some edge connecting vertices
iji_jij and
ijmodk+1i_{j\bmod k+1}ijmodk+1 in the graph) is simple if and only if each
edge appears at most once in it.
To prove that you really found the cycle, you need to output the vertices on the cycle in order.
It is guaranteed that there is at least one cycle in the graph.