No.1190 Points
Problem Statement
You are given an undirected graph with $N$ vertices and $M$ edges, containing no self-loops or multiple edges.
The $ i (1 \le i \le M)$-th edge connects vertex $u_i$ and vertex $v_i$.
When moving from vertex $S$ to vertex $G$ while traversing edges exactly $P$ times in total, find all vertices that may be passed through (including $S, G$).
The writer has confirmed that this problem can get AC using PyPy3, but it has not been confirmed whether AC is possible with Python3.
Please be very careful when submitting in Python.
Input
$N\ M\ P$ $S\ G$ $u_1\ v_1$ $u_2\ v_2$ $\vdots$ $u_M\ v_M$
All inputs are integers.
$2 \le N \le 10^5$
$1 \le M \le min(10^5,N \times (N-1)/2)$
$1 \le P \le 10^9$
$1 \le S, G \le N$
$S \neq G$
$1 \le u_i , v_i \le N$
$ u_i \neq v_i $
When $ i \neq j $, $ (u_i, v_i) \neq (u_j, v_j) $ and $ (u_i, v_i) \neq (v_j, u_j) $
Output
First, output the number $K$ of vertices that may be passed through, and then, on the following $K$ lines, output the vertices that may be passed through in ascending order.
However, if no movement satisfying the condition is possible, output $-1$.
Print a newline at the end.
Sample
Sample 1
Input
6 5 3 1 4 1 2 1 3 1 4 2 5 3 6
Output
4 1 2 3 4
There are $(1→2→1→4),(1→3→1→4),(1→4→1→4)$, a total of 3 ways to go from point 1 to point 4 while traversing edges 3 times.
Sample 2
Input
4 3 4 1 4 1 2 2 3 3 4
Output
-1
Sample 3
Input
10 9 5 1 10 7 2 4 9 5 3 1 9 2 9 8 7 8 5 6 4 10 2
Output
6 1 2 4 7 9 10
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
AndrewK
Rho