No.2674 k-Walk on Bipartite
Problem Statement
For vertices $s, t$ of a graph, a route that starts at $s$ and reaches $t$ by repeating a move to an adjacent vertex $k$ times is called a walk of length $k$ from $s$ to $t$.
First, eoeo came up with the following problem.
頂点集合 $V$ と辺集合 $E$ からなる単純無向二部グラフ $G$ 、その頂点 $s, t$、正整数 $k$ が与えられます。 グラフ $G$ に $s$ から $t$ への長さ $k$ の歩道が存在するか判定してください。
However, this is too simple as it stands. nu50218 added a twist to the problem above: instead of the edge set $E$, the input gives $F$, which is obtained by deleting $0$ or more edges from $E$. Solve the following modified problem.
You are given the number of vertices $N$ of a simple undirected bipartite graph $G$, a subset $F \subseteq E$ of its edge set, vertices $s, t$, and a positive integer $k$.
Based only on the given information, print:
Yesif it is certain that a walk of length $k$ from $s$ to $t$ exists in the graph $G$,Noif it is certain that no such walk exists,Unknownif neither of the above holds.
Formal Problem Statement
More strictly, considering every simple undirected bipartite graph $H$ with $N$ vertices that contains the graph $(V, F)$ as a subgraph,
- print
Yesif the graph $H$ always has a walk of length $k$ from $s$ to $t$, - print
Noif the graph $H$ never has a walk of length $k$ from $s$ to $t$,
and print Unknown if neither of the above holds.
Input
The input is given from Standard Input in the following format.
The $N$ vertices of the graph are numbered $1, 2, \dots, N$.
$M = |F|$, and $A_i, B_i$ are the endpoints of the $i$-th edge of $F$.
$N$ $M$ $s$ $t$ $k$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_M$ $B_M$
Output
Print the answer on a single line to Standard Output, followed by a newline.
Constraints
The input satisfies the following constraints.
- All input values are integers.
- $1 \leq N \leq 2 \times 10^5$
- $0 \leq M \leq 2 \times 10^5$
- $1 \leq s, t \leq N$
- $1 \leq k \leq 10^9$
- $1 \leq A_i < B_i \leq N$
- If $i \neq j$, then $(A_i, B_i) \neq (A_j, B_j)$
- The graph $(V, F)$ is bipartite.
Sample
Sample 1
Input
4 3 1 4 5 1 2 2 3 3 4
Output
Yes
The edge set $E$ is either $F$ or $F$ with the edge $\{1, 4\}$ added. In the latter case, for example, $1 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 4$ exists as a walk of length $5$ from vertex $1$ to vertex $4$.
Sample 2
Input
4 3 1 3 3 1 2 2 3 3 4
Output
No
The edge set $E$ is either $F$ or $F$ with the edge $\{1, 4\}$ added. In either case, it can be shown that no walk of length $3$ from vertex $1$ to vertex $3$ exists.
Sample 3
Input
4 3 1 4 1 1 2 2 3 3 4
Output
Unknown
The edge set $E$ is either $F$ or $F$ with the edge $\{1, 4\}$ added. In the latter case, for example, $1 \rightarrow 4$ exists as a walk of length $1$ from vertex $1$ to vertex $4$. On the other hand, it can be shown that no such walk exists in the former case.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Xelmeph
null
ngtkana
eoeo