# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941176 | sapientsapiens | Bosses (BOI16_bosses) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[1] = 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |