Submission #163684

#TimeUsernameProblemLanguageResultExecution timeMemory
163684alexandra_udristoiuBosses (BOI16_bosses)C++14
100 / 100
897 ms860 KiB
#include<iostream> #include<vector> #include<cstring> #define DIM 5005 using namespace std; int n, i, j, m, x, sum, sol; int viz[DIM], niv[DIM], c[DIM]; vector<int> v[DIM]; void bfs(int srs){ int nod, vecin, i, j, p, u; p = u = viz[srs] = 1; c[1] = srs; niv[srs] = 1; while(p <= u){ nod = c[p]; sum += niv[nod]; p++; for(j = 0; j < v[nod].size(); j++){ vecin = v[nod][j]; if(viz[vecin] == 0){ viz[vecin] = 1; niv[vecin] = 1 + niv[nod]; c[++u] = vecin; } } } if(u != n){ sum = 1000000000; } } int main(){ cin>> n; for(i = 1; i <= n; i++){ cin>> m; for(j = 1; j <= m; j++){ cin>> x; v[x].push_back(i); } } sol = 1000000000; for(i = 1; i <= n; i++){ memset(viz, 0, sizeof(viz) ); sum = 0; bfs(i); sol = min(sol, sum); } cout<< sol; }

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:18:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
        for(j = 0; j < v[nod].size(); j++){
                   ~~^~~~~~~~~~~~~~~
bosses.cpp:10:20: warning: unused variable 'i' [-Wunused-variable]
    int nod, vecin, i, j, p, u;
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...