Minus One
Time limit2sMemory limit512 MB
Count the non-edges whose addition shortens the shortest s-t path by exactly one, given an undirected graph with up to 100,000 vertices.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Shortest path, Combinatorics
- Solved
- No attempts yet
Problem
Ikuta is unusually attached to undirected graphs. Among pairs consisting of an undirected graph and two of its vertices , he likes the ones with large "beauty". The "beauty" of a pair is the number of edges ( and are two distinct vertices of ) such that the length of the shortest path from to in is exactly 1 greater than the length of the shortest path from to in the undirected graph obtained by adding to .
Your job is to write a program that computes this "beauty" for a given pair .
Input
The input is given in the following format.
...
...
First, the integers , which denote the number of vertices of the undirected graph, the number of edges, and two vertices, are given. Lines 2 through each give two vertices connected by an edge. (The vertex set of is .)
Output
Let the given graph be . Print the "beauty" of the pair on one line.
Constraints
Each variable in the input satisfies the following constraints.
-
-
-
-
and are different
-
It is guaranteed that is reachable from