# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954601 | 2024-03-28T08:08:13 Z | sapientsapiens | Bosses (BOI16_bosses) | C++14 | 1 ms | 356 KB |
#include <iostream> #include <vector> #include <queue> using namespace std; int n; vector <int> followers[5005]; int main() { cin >> n; for(int i = 0; i < n; i++) { int k; cin >> k; for(int j = 0; j < k; j++) { int a; cin >> a; followers[a].push_back(i + 1); } } int mi = 2e9; for(int i = 1; i <= n; i++) { //calculate the total sum of salaries when i is the ultimate boss of the company queue <pair<int, int> > q; q.push({i, 1}); bool visited[5005] = {false}; int sum = 0; visited[i] = true; while(!q.empty()) { pair <int, int> now = q.front(); q.pop(); for(int j = 0; j < followers[now.first].size(); j++) { if(!visited[followers[now.first][j]]) { visited[followers[now.first][j]] = true; q.push({followers[now.first][j], now.second + 1}); } } sum += now.second; } mi = min(mi, sum); } cout << mi; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 356 KB | Output is correct |
3 | Incorrect | 1 ms | 356 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 356 KB | Output is correct |
3 | Incorrect | 1 ms | 356 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 356 KB | Output is correct |
3 | Incorrect | 1 ms | 356 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |