QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100

#23262. Finding the Rank

통계

$N$ students took part in the KOI final round. Represent them by the integers from $1$ to $N$. After the contest, instead of announcing every student's rank, the contest headquarters tells any two students $A,B$ who visit which of them did better. No two or more students have tied scores.

Students curious about their overall ranks formed pairs and asked the headquarters a total of $M$ questions. Given the student $X$ whose rank is sought and the headquarters' answers, find and print the range of possible ranks of $X$. Naturally the rank is between $1$, meaning best overall, and $N$, meaning worst overall, but print the most precise answer that can be deduced from the answers.

Input

The following information is given on standard input. The first line contains three space-separated integers $N,M,X$ ($2\le N\le10^5$, $1\le M\le\min(\frac{N(N-1)}{2},5\times10^5)$, $1\le X\le N$). Each of the next $M$ lines contains two integers $A,B$, meaning that student $A$ did better than student $B$. The same pair $A,B$ is never given on more than one line, and the information is guaranteed to be correct.

Output

Print two integers $U,V$ ($1\le U\le V\le N$) to standard output. They mean that the best possible rank of student $X$ is $U$ and the worst possible rank is $V$. If student $X$ has exactly one possible rank, then $U=V$.

Subtasks

  • Subtask 1 is worth 12 of the total 100 points and has $N\le10$.
  • Subtask 2 is worth 11 of the total 100 points and has $N\le1,000$, $M=N(N-1)/2$.
  • Subtask 3 is worth 34 of the total 100 points and has $N\le1,000$.
  • Subtask 4 is worth 43 of the total 100 points and has no constraints beyond the original ones.

Examples

Input 1

5 4 1
1 2
2 3
3 4
4 5

Output 1

1 1

Input 2

5 3 1
2 3
3 4
4 5

Output 2

1 5

Input 3

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

Output 3

1 2

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.