Submission #197122

#TimeUsernameProblemLanguageResultExecution timeMemory
197122dantoh000Bosses (BOI16_bosses)C++14
100 / 100
988 ms760 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adjlist[5005]; int d[5005]; queue<int> q; int main(){ int n; scanf("%d",&n); for (int i = 1; i <= n; i++){ int k; scanf("%d",&k); while (k--){ int x; scanf("%d",&x); adjlist[x].push_back(i); } } int ans = 1000000000; for (int i = 1; i <= n; i++){ memset(d,-1,sizeof(d)); d[i] = 0; q.push(i); while (q.size()){ int u = q.front(); q.pop(); for (auto v : adjlist[u]){ if (d[v] == -1){ d[v] = d[u]+1; q.push(v); } } } int sum = 0; for (int i = 1; i <= n; i++){ if (d[i] == -1) goto done; //printf("%d ",d[i]); sum += d[i]+1; } //printf("\n"); ans = min(ans,sum); done:; } printf("%d",ans); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bosses.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
         ~~~~~^~~~~~~~~
bosses.cpp:14:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...