Loading...
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
Test Cases
# CPU Memory Points
1 12 ms 3456 kb 0 Wrong Answer
2 0 ms 0 kb 0 Skipped
3 0 ms 0 kb 0 Skipped
4 0 ms 0 kb 0 Skipped
5 0 ms 0 kb 0 Skipped
Source Code
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4.  
  5. using namespace std;
  6.  
  7. struct Employee {
  8. int id;
  9. int initialBalance;
  10. int finalBalance;
  11. vector<int> subordinates;
  12. };
  13.  
  14. unordered_map<int, Employee> employees;
  15.  
  16. void distributeBonuses(int teamLeader, int bonus) {
  17. Employee& leader = employees[teamLeader];
  18. leader.finalBalance += bonus * 2;
  19.  
  20. for (int subordinate : leader.subordinates) {
  21. Employee& emp = employees[subordinate];
  22. emp.finalBalance += bonus;
  23. }
  24. }
  25.  
  26. void dfs(int empId) {
  27. Employee& emp = employees[empId];
  28.  
  29. for (int subordinate : emp.subordinates) {
  30. dfs(subordinate);
  31. emp.finalBalance += employees[subordinate].finalBalance;
  32. }
  33. }
  34.  
  35. int main() {
  36. int t;
  37. cin >> t;
  38.  
  39. while (t--) {
  40. int n, q;
  41. cin >> n >> q;
  42.  
  43. employees.clear();
  44.  
  45. for (int i = 1; i <= n; i++) {
  46. int initialBalance;
  47. cin >> initialBalance;
  48. employees[i] = {i, initialBalance, 0, {}};
  49. }
  50.  
  51. for (int i = 0; i < n - 1; i++) {
  52. int a, b;
  53. cin >> a >> b;
  54. employees[a].subordinates.push_back(b);
  55. }
  56.  
  57. for (int i = 0; i < q; i++) {
  58. int leader, bonus;
  59. cin >> leader >> bonus;
  60. distributeBonuses(leader, bonus);
  61. }
  62.  
  63. dfs(1); // Start DFS from the head of the company
  64.  
  65. for (int i = 1; i <= n; i++) {
  66. cout << employees[i].finalBalance << " ";
  67. }
  68. cout << endl;
  69. }
  70.  
  71. return 0;
  72. }
  73.