Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int mod = 1e9 + 7;
- int arr[100003];
- vector < vector <int> > graph;
- void bfs(int src, int x, int y)
- {
- int i, val, d = 0;
- queue <int> q;
- q.push(src);
- q.push(-1);
- while(! q.empty())
- {
- val = q.front();
- q.pop();
- if(val == -1)
- {
- d ++;
- if(! q.empty())
- q.push(-1);
- }
- else
- {
- arr[val] += (x + d * y) % mod;
- for(i = 0; i < graph[val].size(); i ++)
- q.push(graph[val][i]);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- int i, n, u, v, que, x, y;
- cin >> n;
- graph.resize(n + 1);
- for(i = 1; i < n; i ++)
- {
- cin >> u >> v;
- graph[u].push_back(v);
- }
- cin >> que;
- while(que --)
- {
- cin >> u >> x >> y;
- bfs(u, x, y);
- }
- for(i = 1; i <= n; i ++)
- cout << arr[i] << '\n';
- return 0;
- }
Add Comment
Please, Sign In to add comment