Practice on Toph
Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.
Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.
There are N cities in the country AjobDesh and M one way roads connecting the cities.
There lives exactly one AjobPrani in each of the N cities. Every AjobPrani must visit at least one other AjobPrani if there is a path to visit. If possible then he should also return to his home town.
Find how many AjobPrani are unable to return to his home town.
First line contains the number of test cases T(1≤ T ≤10).
For each test case:
First line consists of two integers denoting N(1≤ N ≤100000) and M(0≤ M ≤200000).
Next M lines consist of two integers A and B denoting there is a directed road from A to B (1≤ A,B ≤N).The graph can contain self loops.
For every test case, you need to print “Case T: ” (where T is the test case number) followed by the number of AjobPrani who can’t return.
Input  Output 

1 5 6 1 2 2 3 2 5 5 3 5 1 4 5  Case 1: 1 

51% Solution Ratio
NirjhorEarliest,
EdgedancerFastest, 0.1s
EdgedancerLightest, 8.7 MB
NirjhorShortest, 1115B
Login to submit
For any node in an SCC consisting of 2 or more node we can visit any other city and come back to tha...