S에서 T로 가는 길이 10^100 이하인 모든 워크 중 색 순열이 사전순으로 가장 작은 것을 찾고, 불가능하거나 10^6을 넘으면 해당 문구를 출력한다.
어려움8그래프그리디BFS정렬아직 제출이 없습니다시간 제한2초메모리 제한1024 MBThere is a directed graph G with N nodes and M edges. Each node is numbered 1 through N, and each edge is numbered 1 through M. For each i (1≤i≤M), edge i goes from vertex u_i to vertex v_i and has a unique color c_i.
A walk is defined as a sequence of edges e_1, e_2, ⋯, e_l where for each 1≤k<l, v_e_k (the tail of edge e_k) is the same as u_e_k+1 (the head of edge e_k+1). We can say a walk e_1, e_2, ⋯, e_l starts at vertex u_e_1 and ends at vertex v_e_l. Note that the same edge can appear multiple times in a walk.
The color sequence of a walk e_1, e_2, ⋯, e_l is defined as c_e_1, c_e_2, ⋯, c_e_l.
Consider all color sequences of walks of length at most 10100 from vertex S to vertex T in G. Write a program that finds the lexicographically minimum sequence among them.
The first line of the input contains four space-separated integers N, M, S, and T (1≤N≤100,000, 0≤M≤300,000, 1≤S≤N, 1≤T≤N, S=T).
Then M lines follow: the i (1≤i≤M)-th of them contains three space-separated integers u_i, v_i and c_i (1≤u_i,v_i≤N, u_i=v_i, 1≤c_i≤109); it describes a directional edge from vertex u_i to vertex v_i with color c_i.
The graph doesn't have multiple edges or loops, and each edge has a unique color. Formally, for any 1≤i<j≤M, c_i=c_j and (u_i, v_i)=(u_j, v_j) holds.
If there is no walk from vertex S to vertex T, print "IMPOSSIBLE". (without quotes)
Otherwise, let's say a_1, a_2, ⋯, a_l is the lexicographically minimum sequence among all color sequences of length at most 10100 from vertex S to vertex T.
TOO LONG". (without quotes)Sequence p_1,p_2,⋯,p_n is lexicographically smaller than another sequence q_1,q_2,⋯,q_m if and only if one of the following holds: