BOJ - 18243 - Small World Network

Updated:

import sys
from collections import deque

def BFS(idx, graph, check, N):
    dq = deque()
    check[idx] = 0
    dq.append(idx)

    while dq:
        temp = dq.popleft()
        for i in range(len(graph[temp])):
            if check[graph[temp][i]] == -1:
                dq.append(graph[temp][i])
                check[graph[temp][i]] = check[temp] + 1

def solution():
    N, K = map(int, sys.stdin.readline().split())
    graph = [[] for _ in range(N + 1)]
    for i in range(K):
        a, b = map(int, sys.stdin.readline().split())
        graph[a].append(b)
        graph[b].append(a)

    for i in range(1, N+1):
        check = [-1] * 101
        BFS(i, graph, check, N)
        for j in range(1, N+1):
            if check[j] == -1 or check[j] > 6:
                print("Big World!")
                return

    print("Small World!")

solution()

https://www.acmicpc.net/problem/18243

Categories:

Updated:

Leave a comment