CodeNation | Online Test | Graph Queries
Anonymous User
452

You are given a graph with A nodes and M edges. You have to perform Q queries of two types on it:
Initially value at all nodes is 0.

1 v x - For each neighbor of v,add x to its value.
2 v 0- Find sum of values at all neighbors of v.(modulo 10^9+7)

Two nodes u,v are considered neighbors if and only if there exists an edge between them.
Note: There are no self loops or multiple edges in the graph.

Problem Constraints
1<=A<=10^5
1<=M<=10^5

Your function should return a single array-consiting answers of all queries of second type in the same order they were in input.

I could not come up with an optimized approach. Any suggestion is welcome.

Comments (2)