Planning a Trip

Time limit2sMemory limit128 MB

Summary
Given a directed graph, find the maximum number of distinct cities visitable on a walk from S to T, allowing revisits of cities and edges.
Level

Hard8 of 10

Topics
Graph, DFS, Dynamic programming
Solved
No attempts yet

Problem

Taehui wants to get away from work and go on vacation. After some research, Taehui chooses NN cities to visit. At first, it seemed that flights would be enough to plan the trip, but not every pair of cities is connected by a flight.

There are MM flight routes in total, and each route can be used in only one direction. Taehui will start in city SS and finish the trip in city TT.

Given the cities and flight routes, find the maximum number of distinct cities that can be visited during a trip from city SS to city TT. A city is counted only once even if it is visited multiple times. Cities may be revisited any number of times, and the same flight route may also be used multiple times.

Input

The first line contains four integers NN, MM, SS, and TT. (1≤N≤10 000, 1≤M≤100 000, 1≤S,T≤N)(1 \le N \le 10\,000,\ 1 \le M \le 100\,000,\ 1 \le S,T \le N)

Each of the next MM lines contains two distinct integers AA and BB describing one flight route. (1≤A,B≤N, A≠B)(1 \le A,B \le N,\ A \ne B) This means there is a route from city AA to city BB.

Output

Print the maximum number of distinct cities that can be visited. If it is impossible to travel from city SS to city TT, print 0.

Examples1

  1. Example 1

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