#C8852. Maximum Infected Computers
Maximum Infected Computers
Maximum Infected Computers
You are given a network of computers represented as a directed graph. There is an initially infected computer S from which the infection spreads. A computer u can infect computer v if there exists a directed edge from u to v. Your task is to compute the maximum number of computers that can be infected, i.e., the number of computers reachable from S via a sequence of directed edges.
Formally, if we define the set of infected computers as \( I = \{ v \mid \exists \text{ a path from } S \text{ to } v \}\) then you need to output \(|I|\), the cardinality of this set.
inputFormat
The input is given from standard input (stdin).
The first line contains an integer (T), the number of test cases. For each test case, the first line contains three integers (N), (M), and (S) where:
- \(N\) is the number of computers (nodes).
- \(M\) is the number of directed connections (edges).
- \(S\) is the index of the initially infected computer.
outputFormat
For each test case, output a single integer on a new line that represents the maximum number of computers that can get infected starting from computer (S). The output should be written to standard output (stdout).## sample
1
4 3 1
1 2
2 3
3 4
4
</p>