To send a message, server x connects to two different servers y and z (x != y, y != z, z != x).
The two servers are connected only if the distance between them is divisible by signalSpeed
.
It then sends the signal across the network.
For each server i, the company wants to know the number of disjoint pairs of servers through which the server can send a message.
Return an array of serverNodes
integers, where the ith integer represents the number of disjoint pairs of serfvers (j, k) through which server i can send a message.
- serverNodesQuantity = 4
- serversFrom = [1, 1, 2]
- serversTo = [2, 3, 4]
- serverWeights = [2, 5, 3]
- signalSpeed = 5
graph TD
1 -- 2 --> 2
1 -- 5 --> 3
2 -- 3 --> 4
For server 1, the valid pairs are (3, 4) and (4, 3).
The distances sum to 5 between 1 and 4 and between 1 and 3 are divisible by signalSpeed = 5
.
For server 2, there are no valid pairs.
Distances are 3, 2 and 7 to servers 4, 1 and 3 respectively.
For server 3, the valid pairs are (1, 4) and (4, 1).
For server 4, the valid pairs are (1, 3) and (3, 1).
Return the number of pairs for each server. In this case, is [2, 0, 2, 2]
Complete the function getNumPairs
in the editor below.
getNumPairs
has the following parameters:
int serverNodesQuantity
: the number of serversint[] serversFrom[serverNodesQuantity - 1]
: one end of the edgeint[] serversTo[serverNodesQuantity - 1]
: other end of the edgeint[] serverWeights[serverNodesQuantity - 1]
: the distance between the connected serversint signalSpeed
: the speed of the signal
- 2 <=
serverNodesQuantity
<= 1000 - 1 <=
serversFrom[i]
,serversTo[i]
<=n
- 1 <=
serversWeights[i]
<= 10**6 - 1 <=
signalSpeed
<= 1000