Submission #218617

#TimeUsernameProblemLanguageResultExecution timeMemory
218617Ruxandra985Bosses (BOI16_bosses)C++14
67 / 100
1594 ms640 KiB
#include <bits/stdc++.h> #define DIMN 5010 using namespace std; priority_queue <pair <int,int> > h; vector <int> v[DIMN]; int d[DIMN] , tt[DIMN] , lvl[DIMN]; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , i , k , x , sol , root , nod , vecin , niv , j , sum; fscanf (fin,"%d",&n); for (i = 1 ; i <= n ; i++){ fscanf (fin,"%d",&k); for (j = 1 ; j <= k ; j++){ fscanf (fin,"%d",&x); v[x].push_back(i); /// x poate fi seful lui i } } sol = 2000000000; for (root = 1 ; root <= n ; root++){ h.push(make_pair(-1 , root)); memset (lvl , 0 , sizeof(lvl)); lvl[root] = 1; tt[root] = 0; while (!h.empty()){ nod = h.top().second; niv = -h.top().first; h.pop(); if (lvl[nod] != niv) continue; for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i]; if (lvl[vecin] == 0 || lvl[vecin] > lvl[nod] + 1){ lvl[vecin] = lvl[nod] + 1; tt[vecin] = nod; h.push(make_pair(-lvl[vecin] , vecin)); } } } sum = 0; for (i = 1 ; i <= n ; i++){ sum += lvl[i]; if (tt[i] == 0 && i != root){ sum = 2000000000; break; } } sol = min(sol , sum); } fprintf (fout,"%d",sol); return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:34:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i = 0 ; i < v[nod].size() ; i++){
                          ~~^~~~~~~~~~~~~~~
bosses.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d",&n);
     ~~~~~~~^~~~~~~~~~~~~
bosses.cpp:14:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&k);
         ~~~~~~~^~~~~~~~~~~~~
bosses.cpp:16:20: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             fscanf (fin,"%d",&x);
             ~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...