#P11976. Dangerous Lines in a Communication Network
Dangerous Lines in a Communication Network
Dangerous Lines in a Communication Network
A communication network consists of N computers numbered from 1 to N and M bidirectional communication lines connecting two distinct computers. The network is said to be connected if any two computers can communicate via one or more lines; otherwise, it is disconnected.
For each communication line c, its danger score is defined as follows:
- For each computer i, after removing line c, if the network becomes disconnected upon the removal of computer i (i.e. the remaining network is not fully connected), then computer i is called a dangerous computer.
- The danger score of line c is the number of dangerous computers in the network after the removal of line c.
Your task is to compute the danger score for every line.
You need to implement the following function:
[ vector find_num_critical(int N, vector< pair<int, int> > E) ]
where:
- N denotes the number of computers.
- E is an array of M pairs, each representing a communication line connecting two different computers.
- The function should return an integer array of length M where the i-th integer denotes the danger score of the i-th communication line.
Note: Do not perform any standard input/output operations anywhere in your submitted source code.
inputFormat
The function will be called with the following parameters:
- An integer N representing the number of computers.
- A vector (or array) E of M pairs of integers, with each pair (u, v) indicating a bidirectional line between computer u and v.
outputFormat
Return an array of M integers where the i-th integer is the danger score of the i-th communication line (i.e. the number of "dangerous computers" when that particular line is removed from the network).
sample
4 4
1 2
2 3
3 4
4 1
2 2 2 2