Submission #46265

#TimeUsernameProblemLanguageResultExecution timeMemory
46265ikura355Bosses (BOI16_bosses)C++14
100 / 100
640 ms1476 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int maxn = 5000 + 5; const ll inf = 1e9; int n; vector<int> way[maxn]; int d[maxn]; queue<int> q; ll bfs(int x) { memset(d,0,sizeof(d)); d[x] = 1; q.push(x); while(!q.empty()) { int u = q.front(); q.pop(); for(auto v : way[u]) { if(!d[v]) { d[v] = d[u]+1; q.push(v); } } } ll sum = 0; for(int x=1;x<=n;x++) { sum += d[x]; if(d[x]==0) return inf; } return sum; } int main() { scanf("%d",&n); for(int x=1;x<=n;x++) { int m; scanf("%d",&m); while(m--) { int y; scanf("%d",&y); way[y].push_back(x); } } ll ans = inf; for(int x=1;x<=n;x++) ans = min(ans, bfs(x)); printf("%lld",ans); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bosses.cpp:31:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int m; scanf("%d",&m);
          ~~~~~^~~~~~~~~
bosses.cpp:33:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int y; scanf("%d",&y);
           ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...