BOJ - 2458 - 키 순서

Updated:

import sys

def solution():
    N, M = map(int, sys.stdin.readline().split())
    arr = [[0] * N for _ in range(N)]
    for _ in range(M):
        x, y = map(int, sys.stdin.readline().split())
        arr[x-1][y-1] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if (arr[i][k] and arr[k][j]):
                    arr[i][j] = 1

    ret = 0
    for i in range(N):
        rank = 0
        for j in range(N):
            rank += arr[i][j] + arr[j][i] 
        if rank == N - 1: 
            ret += 1
    print(ret)
    
solution()

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

Categories:

Updated:

Leave a comment