~/algor $ cat problems/graf-yetib-boriladigan
Reachable vertices
Easy
1000 ms
128 MB
28%
A graph with $n$ vertices and $m$ directed edges is given: an edge $u \to v$ can be traversed only from $u$ to $v$. How many vertices can be reached along the edges from vertex $s$? $s$ itself also counts.
Input
The first line contains three integers: $n$, $m$ and $s$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — an edge $u \to v$.
Output
One integer — the number of reachable vertices.
Note
$1 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le s, u, v \le n$
There may be multiple edges and loops.
Examples
Input #1
5 5 1 1 2 2 3 3 1 4 3 2 5
Output #1
4
Input #2
4 2 3 1 3 2 3
Output #2
1