Problem 2987 --Blow up the city

2987: Blow up the city

"
Time Limit $5$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Country A and B are at war. Country A needs to organize transport teams to deliver supplies toward some command center cities. 

In order to ensure the delivery works efficiently, all the roads in country A work only one direction. Therefore, map of country A can be regarded as DAG( Directed Acyclic Graph ). Command center cities only received supplies and not send out supplies. 

Intelligence agency of country B is credibly informed that there will be two cities carrying out a critical transporting task in country A. 

As long as **any** one of the two cities can not reach a command center city, the mission fails and country B will hold an enormous advantage. Therefore, country B plans to destroy one of the nn cities in country A and all the roads directly connected. (If a city carrying out the task is also a command center city, it is possible to destroy the city to make the mission fail) 

Now country B has made qq hypotheses about the two cities carrying out the critical task. 
Calculate the number of plan that makes the mission of country A fail.
The first line contains a integer TT (1≤T≤10)(1≤T≤10), denoting the number of test cases.

In each test case, the first line are two integers n,mn,m, denoting the number of cities and roads(1≤n≤100,000,1≤m≤200,000)(1≤n≤100,000,1≤m≤200,000)
Then mm lines follow, each with two integers uu and vv, which means there is a directed road from city uu to vv (1≤u,v≤n,u≠v)(1≤u,v≤n,u≠v)

The next line is a integer q, denoting the number of queries (1≤q≤100,000)(1≤q≤100,000) 
And then qq lines follow, each with two integers aa and bb, which means the two cities carrying out the critical task are aa and bb (1≤a,b≤n,a≠b)(1≤a,b≤n,a≠b)

A city is a command center if and only if there is no road from it (its out degree is zero).
For each query output a line with one integer, means the number of plan that makes the mission of country A fail.
2
8 8
1 2
3 4
3 5
4 6
4 7
5 7
6 8
7 8
2
1 3
6 7
3 2
3 1
3 2
2
1 2
3 1
4
3
2
2

推荐代码 查看2987 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$520 $ms] intLSY 481215 2019-10-09 21:32:49
内存最少[$26680 $KB] intLSY 481215 2019-10-09 21:32:49
第一AC intLSY 481215 2019-10-09 21:32:49
第一挑战 intLSY 481215 2019-10-09 21:32:49

赛题来源/所属竞赛 2019 Multi-University Training Contest 3 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛