PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000028. Hành trình qua các thành phố (Tour)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hành trình qua các thành phố (Tour)
Tour
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Count ordered pairs such that is reachable from in a directed graph, including zero-edge walks .
Input
Integers , followed by directed edges ; vertices are 1-indexed.
Output
Print the number of reachable ordered pairs.
Subtasks
- Subtask 1 (40 points): ; , ; distinct directed edges and .
- Subtask 2 (60 points): , ; distinct directed edges and .
Examples
Input
3 3
1 2
2 3
3 2
Output
7
Explanation
City 1 can reach 1, 2, 3; city 2 can reach 2, 3; city 3 can reach 3, 2. Thus the total is , including the three zero-edge routes.