100 #ABC204C. [ABC204C] Tour

[ABC204C] Tour

Score : 300300 points

Problem Statement

The republic of AtCoder has NN cities numbered 11 through NN and MM roads numbered 11 through MM.

Road ii leads from City AiA_i to City BiB_i, but you cannot use it to get from City BiB_i to City AiA_i.

Puma is planning her journey where she starts at some city, travels along zero or more roads, and finishes at some city.

How many pairs of cities can be the origin and destination of Puma's journey? We distinguish pairs with the same set of cities in different orders.

Constraints

  • 2N20002 \leq N \leq 2000
  • 0Mmin(2000,N(N1))0 \leq M \leq \min(2000,N(N-1))
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • AiBiA_i \neq B_i
  • (Ai,Bi)(A_i,B_i) are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

Print the answer.

3 3
1 2
2 3
3 2
7

We have seven pairs of cities that can be the origin and destination: (1,1),(1,2),(1,3),(2,2),(2,3),(3,2),(3,3)(1,1),(1,2),(1,3),(2,2),(2,3),(3,2),(3,3).

3 0
3

We have three pairs of cities that can be the origin and destination: (1,1),(2,2),(3,3)(1,1),(2,2),(3,3).

4 4
1 2
2 3
3 4
4 1
16

Every pair of cities can be the origin and destination.