305610: CF1062F. Upgrading Cities
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Upgrading Cities
题意翻译
给定一张有向无环图,定义重要的节点$x$为满足不存在一个节点$y$,使得既不能从$x$到$y$,也不能从$y$到$x$的节点,次重要的节点为删除某个节点后能满足上面条件的节点(不包括重要的节点),求重要的节点和次重要的节点一共有多少个。 输入:第一行两个整数$n,m$表示节点个数和边的条数,接下来$m$行分别为每条边 输出:一行,即重要的节点和次重要的节点的个数和题目描述
There are $ n $ cities in the kingdom $ X $ , numbered from $ 1 $ through $ n $ . People travel between cities by some one-way roads. As a passenger, JATC finds it weird that from any city $ u $ , he can't start a trip in it and then return back to it using the roads of the kingdom. That is, the kingdom can be viewed as an acyclic graph. Being annoyed by the traveling system, JATC decides to meet the king and ask him to do something. In response, the king says that he will upgrade some cities to make it easier to travel. Because of the budget, the king will only upgrade those cities that are important or semi-important. A city $ u $ is called important if for every city $ v \neq u $ , there is either a path from $ u $ to $ v $ or a path from $ v $ to $ u $ . A city $ u $ is called semi-important if it is not important and we can destroy exactly one city $ v \neq u $ so that $ u $ becomes important. The king will start to act as soon as he finds out all those cities. Please help him to speed up the process.输入输出格式
输入格式
The first line of the input contains two integers $ n $ and $ m $ ( $ 2 \le n \le 300\,000 $ , $ 1 \le m \le 300\,000 $ ) — the number of cities and the number of one-way roads. Next $ m $ lines describe the road system of the kingdom. Each of them contains two integers $ u_i $ and $ v_i $ ( $ 1 \le u_i, v_i \le n $ , $ u_i \neq v_i $ ), denoting one-way road from $ u_i $ to $ v_i $ . It is guaranteed, that the kingdoms' roads make an acyclic graph, which doesn't contain multiple edges and self-loops.
输出格式
Print a single integer — the number of cities that the king has to upgrade.
输入输出样例
输入样例 #1
7 7
1 2
2 3
3 4
4 7
2 5
5 4
6 4
输出样例 #1
4
输入样例 #2
6 7
1 2
2 3
3 4
1 5
5 3
2 6
6 4
输出样例 #2
4