QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22304. 소 경연 대회

Statistics

$N$마리 ($1 \le N \le 100$) 소에게 $1..N$ 번호가 붙어 있으며 프로그래밍 대회에 참가한다. 알다시피 어떤 소들은 다른 소보다 코딩을 잘한다. 각 소의 능력치는 일정하며 모든 참가자의 능력치는 서로 다르다.

대회는 여러 번의 일대일 대결로 진행되며 매번 두 소가 대결한다. 소 $A$의 능력치가 소 $B$보다 높다면 ($1 \le A \le N;1 \le B \le N;A \ne B$) $A$는 항상 $B$를 이긴다.

Farmer John은 능력치에 따라 소의 순위를 매기고자 한다. $M$번 ($1 \le M \le 4{,}500$) 대결 결과가 주어질 때 순위를 정확히 알 수 있는 소의 수를 구하라. 결과가 모순되지 않음이 보장된다.

입력

표준 입력에서 입력을 읽는다.

  • 1번째 줄: 공백으로 구분한 두 정수 $N$, $M$.
  • $2..M+1$번째 줄: 각 줄에 한 대결의 참가자와 결과를 나타내는 두 정수 $A$, $B$가 공백으로 구분되어 주어진다 (첫 정수 $A$가 승자다).

출력

표준 출력에 출력한다.

  • 1번째 줄: 순위를 알 수 있는 소의 수를 나타내는 정수 하나.

예제

입력 1

5 5
4 3
4 2
3 2
1 2
2 5

출력 1

2

참고

소 $2$는 소 $1$, $3$, $4$에게 지므로 이들 중 누구보다도 더 잘하지 못한다. 소 $5$는 소 $2$에게 지므로 $2$는 $5$보다 잘한다. 따라서 $2$는 $4$위, $5$는 $5$위여야 한다. 다른 소의 순위는 알 수 없다.

문제 출제: Neal Wu, 2007

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.