Submission
# | When | Author | Problem | Language | CPU | Memory | |
---|---|---|---|---|---|---|---|
20845 | 2024-06-09 11:39:53 | AHAMMED_99 | Bonus Project | C++ 11 | 12 ms | 3456 kb | Wrong Answer - 1 |
Source Code
#include <iostream> #include <vector> #include <unordered_map> using namespace std; struct Employee { int id; int initialBalance; int finalBalance; vector<int> subordinates; }; unordered_map<int, Employee> employees; void distributeBonuses(int teamLeader, int bonus) { Employee& leader = employees[teamLeader]; leader.finalBalance += bonus * 2; for (int subordinate : leader.subordinates) { Employee& emp = employees[subordinate]; emp.finalBalance += bonus; } } void dfs(int empId) { Employee& emp = employees[empId]; for (int subordinate : emp.subordinates) { dfs(subordinate); emp.finalBalance += employees[subordinate].finalBalance; } } int main() { int t; cin >> t; while (t--) { int n, q; cin >> n >> q; employees.clear(); for (int i = 1; i <= n; i++) { int initialBalance; cin >> initialBalance; employees[i] = {i, initialBalance, 0, {}}; } for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; employees[a].subordinates.push_back(b); } for (int i = 0; i < q; i++) { int leader, bonus; cin >> leader >> bonus; distributeBonuses(leader, bonus); } dfs(1); // Start DFS from the head of the company for (int i = 1; i <= n; i++) { cout << employees[i].finalBalance << " "; } cout << endl; } return 0; }