Count Edges Incident to a NodeEasy

Count Edges Incident to a Node

EasyPractice library · +10 XPgraphsbfsdfs

Given an undirected graph with N nodes and M edges, and a target node T, count the total number of edges that are connected to node T. An edge is connected to node T if T is one of its endpoints.

Input

The first line contains three integers N, M, and T (1 <= T <= N <= 1000, 0 <= M <= 1000). The next M lines each contain two integers u and v, representing an edge between node u and node v (1 <= u, v <= N, u != v).

Output

Print a single integer: the number of edges incident to node T.

Constraints

1 <= T <= N <= 1000, 0 <= M <= 1000. Node labels are 1-indexed.

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5 4 3
1 2
2 3
3 4
4 5
Output
2

Node 3 is connected to edges (2,3) and (3,4), so the count is 2.

Example 2

Input
3 3 1
1 2
1 3
2 3
Output
2

Node 1 is connected to edges (1,2) and (1,3), so the count is 2.

Hints