Submission #218632

#TimeUsernameProblemLanguageResultExecution timeMemory
218632Ruxandra985Bosses (BOI16_bosses)C++14
100 / 100
745 ms760 KiB
#include <bits/stdc++.h> #define DIMN 5010 using namespace std; priority_queue <pair <int,int> > h; deque <int> dq; 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 , taken = 0; 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++){ memset (lvl , 0 , sizeof(lvl)); lvl[root] = 1; sum = 1; taken = 1; dq.push_back(root); while (!dq.empty()){ nod = dq.front(); dq.pop_front(); for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i]; if (lvl[vecin] == 0){ taken++; sum = sum + lvl[nod] + 1; lvl[vecin] = lvl[nod] + 1; dq.push_back(vecin); } } } if (taken == n) sol = min(sol , sum); } fprintf (fout,"%d",sol); return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:33:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i = 0 ; i < v[nod].size() ; i++){
                          ~~^~~~~~~~~~~~~~~
bosses.cpp:12:53: warning: unused variable 'niv' [-Wunused-variable]
     int n , i , k , x , sol , root , nod , vecin ,  niv , j , sum , taken = 0;
                                                     ^~~
bosses.cpp:13: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:15: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:17: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...