A task graph has n tasks. A directed edge u v means task u must be completed before task v. Given a target task t, count how many distinct tasks are ancestors of t — that is, tasks from which t is reachable by following directed edges (not counting t itself). These are exactly the tasks that must be finished, directly or transitively, before t can run. The graph may contain cycles.
Input format
Line 1: two integers n and m — the number of nodes (labeled 0 through n-1) and the number of directed edges.
Each of the next lines: two integers , a directed edge from to (read as: must come before ).
The final line: a single integer , the target task.
Output format
A single integer: the number of distinct nodes from which t is reachable, excluding t.
Constraints
- 1 <= n <= 30
- 0 <= m <= 200
- 0 <= u, v <= n-1, 0 <= t <= n-1 (cycles and self-loops may appear)