102042: [AtCoder]ABC204 C - Tour

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

The republic of AtCoder has $N$ cities numbered $1$ through $N$ and $M$ roads numbered $1$ through $M$.

Road $i$ leads from City $A_i$ to City $B_i$, but you cannot use it to get from City $B_i$ to City $A_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

  • $2 \leq N \leq 2000$
  • $0 \leq M \leq \min(2000,N(N-1))$
  • $1 \leq A_i,B_i \leq N$
  • $A_i \neq B_i$
  • $(A_i,B_i)$ are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$A_1$ $B_1$
$\vdots$
$A_M$ $B_M$

Output

Print the answer.


Sample Input 1

3 3
1 2
2 3
3 2

Sample Output 1

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)$.


Sample Input 2

3 0

Sample Output 2

3

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


Sample Input 3

4 4
1 2
2 3
3 4
4 1

Sample Output 3

16

Every pair of cities can be the origin and destination.

Input

题意翻译

### 题目描述 AtCoder国家包括编号 ${1}$ 到 ${N}$ 的 ${N}$ 个城市和编号为 ${M}$ 的 ${M}$ 条道路。 通过道路 ${i}$ 可以从城市 ${A_i}$ 移动到 ${B_i}$ 。从都市 ${B_i}$ 到都市 ${A_i}$ 不能通行。彪马打算从某个城市开始,使用 ${0}$ 条以上的道路移动,制定以某个城市为终点的旅行计划。 作为起点和终点的城市组合,有几种? ### 输入格式 输入的以下形式由标准输入给出。 $ {N M } $ $ {A_1 B_1⋮ A_M B_M} $ ### 输出格式 输出一行,包含一个正整数,表示彪马旅行问题的可能性的种数。

加入题单

算法标签: