info

MAPS OS v1.1.4 © 2025

Glory to the Segtree

Glory to the Algorithm.

Salaryman RememberGo home

Login to view input

no submission

Login to submit an answer

Problem Leaderboard

Problem Leaderboard

Salaryman Remember

A salaryman yapping a secret

Image generated by Google Gemini.

After downing four umeshu, the salaryman made a huge mistake, he told someone a secret he should have kept to himself.

He only remembers telling person s... but person s is chatty. This secret may spread faster than Mr. Salaryman's bar tab.

You're given a list of people, identified by integers 1 to n, along with records of conversational relationships. Once someone knows the secret, they will definitely spill it to anyone they talk to. Can you figure out how many people might now know the secret?

Input

  • First line: three values n, m, and s: number of people, number of interactions, and the number corresponding to the original leaker.
  • Next m lines contains two integers a and b: indicating person a and b talk to each other.

Constraints

  • 1 ≤ n ≤ 2 x 104
  • 1 ≤ m ≤ 2 x 104
  • 1 ≤ s ≤ n
  • 1 ≤ a, b ≤ n, a ≠ b

Output

Print the number of people who might now know the secret.

Example

Input:

6 4 1
1 2
2 3
3 4
5 6

Output:

4

Explanation

The secret starts with person 1, who talks to 2, who talks to 3, who talks to 4. All of them could have heard the secret. Persons 5 and 6 are in a separate group.