問題一覧 > 通常問題

No.408 Five-Ring Pick

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 80 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 67
作問者 : 紙ぺーぱー / テスター : btk
お気に入りにしたユーザー ProblemId : 1161 / 自分の提出
問題文最終更新日: 2026-06-25 01:22:20
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 145 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。