F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

CRB and Roads

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 628    Accepted Submission(s): 281


Problem Description
There are $N$ cities in Codeland.
The President of Codeland has a plan to construct one-way roads between them.
His plan is to construct $M$ roads.
But CRB recognized that in this plan there are many redundant roads.
So he decided to report better plan without any redundant roads to President.
Help him!
The road ($u$, $v$) is redundant if and only if there exists a route from $u$ to $v$ without using it.
 

Input
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:
The first line contains two integers $N$ and $M$ denoting the number of cities and the number of roads in the President¡¯s plan.
Then $M$ lines follow, each containing two integers $u$ and $v$ representing a one-way road from $u$ to $v$.
1 ¡Ü $T$ ¡Ü 20
1 ¡Ü $N$ ¡Ü 2 * $10^{4}$
1 ¡Ü $M$ ¡Ü $10^{5}$
1 ¡Ü $u$, $v$ ¡Ü $N$
The given graph is acyclic, and there are neither multiple edges nor self loops.

 

Output
For each test case, output total number of redundant roads.
 

Sample Input
1 5 7 1 2 1 3 1 4 1 5 2 4 2 5 3 4
 

Sample Output
2
 

Author
KUT£¨DPRK£©
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:56:05, Gzip enabled