Submission #954604

#TimeUsernameProblemLanguageResultExecution timeMemory
954604sapientsapiensBosses (BOI16_bosses)C++14
0 / 100
1 ms500 KiB
#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 < (int) 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...