No.408 Five-Ring Pick
Problem Statement
There is a simple undirected graph with $N$ vertices and $M$ undirected edges, and the vertices are numbered from $1$ to $N$.
If this graph has a simple cycle of length $5$ containing vertex $1$, print $\verb|"YES"|$; otherwise, print $\verb|"NO"|$.
An undirected graph is said to have a simple cycle of length $5$ if there exists a vertex set $(a,b,c,d,e)$ satisfying the following conditions.
- $a,b,c,d,e$ are pairwise distinct
- Vertices $a,b$ are adjacent
- Vertices $b,c$ are adjacent
- Vertices $c,d$ are adjacent
- Vertices $d,e$ are adjacent
- Vertices $e,a$ are adjacent
Input
$N$ $M$ $A_1$ $B_1$ $\vdots$ $A_M$ $B_M$
Line $1$ contains $2$ integers $N,\;M(2 \leq N \leq 2 \times 10^{4},\; 0 \leq M \leq \text{min}(N(N-1)/2,\;5 \times 10^{4}))$ separated by a space, representing the number of vertices and the number of edges.
Line $2$ begins the following $M$ lines. On the $i(1 \leq i \leq M)$-th of these lines, $2$ integers $A_i, B_i (1\leq A_i, B_i \leq N)$ are given separated by a space, indicating that there is an edge between vertex $A_i$ and vertex $B_i$.
The graph is guaranteed to be simple. That is, there are no self-loops or multiple edges.
Output
Print the answer in $1$ line.
Sample
Sample 1
Input
5 5 1 2 2 3 3 4 4 5 5 1
Output
YES
This graph is itself a simple cycle graph consisting of $5$ vertices.
Sample 2
Input
5 4 1 2 2 3 3 4 4 5
Output
NO
There is no cycle.
Sample 3
Input
6 6 1 2 2 3 3 4 4 5 5 6 6 2
Output
NO
There is none containing vertex $1$.
Sample 4
Input
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
Output
YES
Removing suitable edges yields a simple cycle graph consisting of $5$ vertices.
Sample 5
Input
7 10 1 2 1 3 1 4 1 5 2 3 2 4 2 6 3 4 3 7 4 5
Output
YES
Removing suitable vertices and edges yields a simple cycle graph consisting of $5$ vertices.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
紙ぺーぱー
btk