아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Popular Cows

시간 제한1초메모리 제한1024 MB

요약
N마리 소와 M개의 인기 관계가 방향 그래프로 주어질 때, 다른 모든 소가 도달할 수 있는 소의 수를 구한다.
난이도

보통10점 중 7점

유형
그래프, DFS, 위상 정렬
정답자
아직 제출이 없습니다

문제

Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 ≤ N ≤ 10,000) cows, you are given up to M (1 ≤ M ≤ 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popular. Since popularity is transitive, if A thinks B is popular and B thinks C is popular, then A will also think that C is popular, even if this is not explicitly specified by an ordered pair in the input. Your task is to compute the number of cows that are considered popular by every other cow.

입력

  • Line 1: Two space-separated integers, N and M
  • Lines 2..1+M: Two space-separated numbers A and B, meaning that A thinks B is popular.

출력

  • Line 1: A single integer that is the number of cows who are considered popular by every other cow.

힌트

Cow 3 is the only cow of high popularity.

예제1

  1. 예제 1

    입력
    3 3
    1 2
    2 1
    2 3
    
    예상 출력
    1