TikTok: Secondary Influencers
TikTok's influencer network can be represented as a tree of g_nodes numbered from 1 to g_nodes. Each connection between influencers is represented by an edge in the tree, where the i-th edge connects the influencers g_from[i] and g_to[i].
Suppose the maximum distance, i.e., the number of connections between any two influencers, is mx. An influencer is considered primary if they lie on the simple path between two influencers u and v such that the distance between u and v is equal to mx. All other influencers are secondary.
Your task is to find the sum of indices of all the secondary influencers.
Complete the function getSecondaryInfluencerSum in the editor.
getSecondaryInfluencerSum has the following parameters:
int g_nodes: the number of influencers in the network.int g_from[g_edges]: one influencer in each connection.int g_to[g_edges]: the other influencer in each connection.
Returns
long int: the sum of indices of the secondary influencers.
1Example 1

2Example 2

3Example 3

Constraints
Limits and guarantees your solution can rely on.