let input = readLine()!.split(separator: " ").map{ Int(String($0))! }
let (N, M) = (input[0], input[1])
var graph: [[Int]] = Array(repeating: [], count: N)
var visited = Array(repeating: false, count: N)
var isArrived = false
for _ in 0..<M {
let input = readLine()!.split(separator: " ").map{ Int(String($0))! }
graph[input[0]].append(input[1])
graph[input[1]].append(input[0])
}
for i in 0..<N {
dfs(i, 1)
if isArrived {
break
}
}
print(isArrived ? 1 : 0)
func dfs(_ number: Int, _ count: Int) {
if count == 5 {
isArrived = true
return
}
visited[number] = true
for node in graph[number] {
if !visited[node] {
dfs(node, count+1)
}
}
visited[number] = false
}
DFS를 사용해 인접 리스트를 탐색하고, 탐색 깊이가 5가 되면 탐색을 종료하고 답을 출력한다.