Under construction

Still being built. Things may change

Passing On a Good Deed

Time limit1sMemory limit1024 MB

Summary
Given a directed graph and a subject K, find the start X (not K) with the most people on some path from X to K, and print X and that count.
Level

Medium6 of 10

Topics
Graph, BFS, Bit manipulation
Solved
No attempts yet

Problem

Sangwon Lee, who has no problems with his character, often shares good deeds about the people around him. People's relationships are tangled, so when you tell someone a good deed about a person, it travels around and eventually reaches that person.

Relationships and good deeds are defined as follows.

  • A relationship is one-way. That is, even if A→BA \rightarrow B holds, B→AB \rightarrow A may not hold.
  • When a relationship A→BA \rightarrow B is given, BB is one of the people close to AA.
  • Each person may hear a good deed several times. Whenever person AA hears a good deed, AA picks one of the people close to them and passes it on.

A good deed only matters once it reaches the person it is about. Suppose a good deed starts from AA and reaches a third person CC. If it can then reach the subject through CC, then AA is called a 'direct good deed spreader' and CC is called an 'indirect good deed spreader'. The subject can also create indirect spreaders, and the subject can become an indirect spreader too. A direct spreader cannot become an indirect spreader.

In the relationships shown above, if the subject is person 3 and the direct spreader is person 1, then the indirect spreader is {2}, which is 1 person.

Sangwon wants to spread a good deed about the subject KK. He does not want to tell many people, so he will pass it to only one direct spreader. He chooses a direct spreader XX (X≠KX \neq K) and passes the good deed to them. What is the maximum number of indirect spreaders that can arise?

Input

The first line contains NN (1≤N≤10,0001 \le N \le 10,000) and MM (0≤M≤100,0000 \le M \le 100,000). These are the number of people and the number of relationships, respectively.

From the second line through line M+1M+1, the MM relationships are given. Each line contains two integers uu and vv (1≤u,v≤N1 \le u, v \le N, u≠vu \ne v) separated by a space. This means a relationship u→vu \rightarrow v. No relationship is given twice.

The last line contains an integer KK (1≤K≤N1 \le K \le N). This is the subject of the good deed.

Output

On the first line, print XX, the direct spreader defined in the problem, and the number of indirect spreaders caused by XX, separated by a space. If several values of XX give the same maximum, print the smallest one. If no indirect spreader can arise, print 0 on the first line.

Hint

If the good deed is passed to person 1, the spreading path is 1→2→3→1→2→4→5→6→7→8→7. The indirect spreaders are {2, 3, 4, 5, 6, 7, 8}, which is 7 people.

Examples2

  1. Example 1

    Input
    11 17
    1 2
    2 3
    3 1
    4 5
    5 6
    5 4
    6 5
    7 8
    8 7
    2 4
    4 7
    6 7
    10 11
    11 9
    8 9
    9 10
    2 7
    7
    
    Expected output
    1 7
    
  2. Example 2

    Input
    4 4
    1 2
    1 3
    2 4
    3 4
    4
    
    Expected output
    1 1