Submission
# | When | Author | Problem | Language | CPU | Memory | |
---|---|---|---|---|---|---|---|
19962 | 2024-05-16 21:24:19 | AHAMMED_99 | Bonus Project | C | 13 ms | 17384 kb | Wrong Answer - 1 |
Source Code
#include <stdio.h> #include <stdlib.h> #define MAX_EMPLOYEES 500005 // Structure to represent each employee node struct Employee { int id; // Employee ID int balance; // Initial account balance int projects; // Number of projects assigned int bonus; // Bonus amount struct Employee *subordinates; // Array of subordinates int numSubordinates; // Number of subordinates }; // Function to perform depth-first traversal void dfs(struct Employee *employees, int id, int bonus) { // Add bonus to current employee's balance employees[id].balance += bonus; // Traverse subordinates recursively for (int i = 0; i < employees[id].numSubordinates; i++) { int subordinateID = employees[id].subordinates[i].id; dfs(employees, subordinateID, bonus); } } int main() { int T; while (T--) { int N, Q; struct Employee employees[MAX_EMPLOYEES]; for (int i = 1; i <= N; i++) { employees[i].id = i; employees[i].projects = 0; employees[i].subordinates = NULL; employees[i].numSubordinates = 0; } // Construct the hierarchy for (int i = 1; i < N; i++) { int A, B; employees[A].numSubordinates++; employees[A].subordinates = realloc(employees[A].subordinates, employees[A].numSubordinates * sizeof(struct Employee)); employees[A].subordinates[employees[A].numSubordinates - 1] = employees[B]; } // Process each project for (int i = 0; i < Q; i++) { int X, Y; // Assign bonus to team leader employees[X].balance += 2 * Y; // Assign bonus to subordinates dfs(employees, X, Y); } // Print the final account balances for (int i = 1; i <= N; i++) { } } return 0; }