====== 키 순서 ====== ===== 풀이 ===== * N의 범위가 다른 것을 제외하고는 [[ps:problems:boj:6156]]과 같은 문제이다. 풀이는 그쪽 참고. ===== 코드 ===== """Solution code for "BOJ 2458. 키 순서". - Problem link: https://www.acmicpc.net/problem/2458 - Solution link: http://www.teferi.net/ps/problems/boj/2458 Tags: [Floyd] """ import sys def main(): N, M = [int(x) for x in sys.stdin.readline().split()] higher_rankers = [set() for _ in range(N)] lower_rankers = [set() for _ in range(N)] for _ in range(M): a, b = [int(x) for x in sys.stdin.readline().split()] higher_rankers[a - 1].add(b - 1) lower_rankers[b - 1].add(a - 1) for i in range(N): for higher_ranker in higher_rankers[i]: lower_rankers[higher_ranker].update(lower_rankers[i]) for lower_ranker in lower_rankers[i]: higher_rankers[lower_ranker].update(higher_rankers[i]) answer = sum(1 for i in range(N) if len(higher_rankers[i]) + len(lower_rankers[i]) == N - 1) print(answer) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:골드_4}}