Build a Bridge

Time limit: 0.5s Memory limit: 256MB Input: Output:


The monkeys at the zoo of Pordenone have NN trees (numbered from 00 to N1N-1) to play on, with MM suspended bridges connecting some pairs of them. The bridges are numbered from 00 to M1M - 1, and bridge ii connects trees UiU_i and ViV_i bidirectionally. There is at most one bridge between any pair of trees, and it is possible to get from tree 00 to every other tree by crossing bridges.

The distance between two tress is the minimum number of bridges one has to cross to get from one tree to the other (without touching the ground).

Alessandro, the zookeeper, wants to add a new bridge to make the monkey area fancier. However, he is facing a problem: the monkey sitting on tree 00 and the one sitting on tree N1N - 1 are sworn enemies, and if he were to make them fight he would be fired instantly. The monkeys would fight if, after installing the new bridge, the distance between tree 00 and N1N - 1 was less than before. Also, Alessandro is not allowed to install a bridge between two trees that are already directly connected by a bridge.

Task

How many possible choices are there for the new bridge that would not get Alessandro fired?

Input data

The input consists of:

  • a line containing integers NN, MM.
  • MM lines, the ii-th of which consisting of integers UiU_{i}, ViV_{i}.

Output data

The output must contain a single line consisting of a 6464-bit integer CC, the number of ways to choose the location of the new bridge.

Constraints and clarifications

  • 1N100 0001 \le N \le 100 \ 000
  • 1M300 0001 \le M \le 300 \ 000
  • 0UiVi<N0 \le U_i \neq V_i < N for each i=0M1i=0\ldots M - 1
  • It is possible to reach any other tree from tree 00 by crossing bridges.
  • There is at most one bridge between any pair of trees.
# Points Constraints
1 0 Examples
2 24 N100N \leq 100, M500M \leq 500
3 33 N5 000N \leq 5 \ 000
4 43 No additional constraints

Example 1

stdin

5 5
0 1
1 2
0 2
2 3
3 4

stdout

1

Explanation

In this sample case, there are 55 trees and 55 bridges. Initially, it is possible to reach tree 44 from tree 00 by crossing 33 bridges: 02340 — 2 — 3 — 4.

  • If Alessandro were to add a bridge between trees 00 and 44 it would be possible to reach tree 44 by crossing 11 bridge: 040 — 4.
  • If he were to add a bridge between trees 00 and 33 it would be possible to reach tree 44 by crossing 22 bridges: 0340 — 3 — 4.
  • If he were to add a bridge between trees 11 and 44 it would be possible to reach tree 44 by crossing 22 bridges: 0140 — 1 — 4.
  • If he were to add a bridge between trees 11 and 33 it would not be possible to reach tree 44 by crossing fewer than 33 bridges.
  • If he were to add a bridge between trees 22 and 44 it would be possible to reach tree 44 by crossing 22 bridges: 0240 — 2 — 4.

The answer is therefore 11, since the only bridge that Alessandro could build without getting fired is 131 — 3.

Example 2

stdin

10 12
5 7
5 0
2 1
6 7
9 8
1 8
3 4
6 5
1 3
9 0
0 1
5 9

stdout

33

Log in or sign up to be able to send submissions!