This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include<vector>
#include <queue>
using namespace std;
long long bfs(int v, vector<vector<int>> &g) {
queue<int> q;
q.push(v);
int n = g.size();
vector<long long> deep(n, 1e10);
deep[v] = 1;
while (q.size() > 0) {
int u = q.front();
q.pop();
for (int i = 0; i < g[u].size(); ++i) {
if (deep[g[u][i]] > 1000000) {
deep[g[u][i]] = deep[u] + 1;
q.push(g[u][i]);
}
}
}
long long summ = 0;
for(int i = 0; i < n; ++i) {
summ += deep[i];
}
return summ;
}
int main()
{
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
for (int j = 0; j < k; ++j) {
int v;
cin >> v;
--v;
g[v].push_back(i);
}
}
long long total_cost = 1000000000000;
for (int i = 0; i < n; ++i) {
long long ans = bfs(i, g);
if(ans < total_cost) {
total_cost = ans;
}
}
cout << total_cost;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'long long int bfs(int, std::vector<std::vector<int> >&)':
bosses.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < g[u].size(); ++i) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |