Submission #99566

#TimeUsernameProblemLanguageResultExecution timeMemory
99566tushar_2658Bosses (BOI16_bosses)C++14
100 / 100
569 ms732 KiB
#include "bits/stdc++.h" using namespace std; int dis[5005]; int n; vector<int> edges[5005]; int bfs(int s){ memset(dis, -1, sizeof dis); dis[s] = 1; queue<int> que; que.push(s); while(!que.empty()){ s = que.front(); que.pop(); for(auto i : edges[s]){ if(dis[i] != -1)continue; dis[i] = dis[s] + 1; que.push(i); } } int ret = 0; for(int i=1; i<=n; i++){ if(dis[i] == -1)return -1; ret += dis[i]; }return ret; } int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ int timer; scanf("%d", &timer); while(timer--){ int x; scanf("%d", &x); edges[x].emplace_back(i); } } int ans = INT_MAX; for(int i=1; i<=n; i++){ int x = bfs(i); if(x == -1)continue; ans = min(ans, x); }cout<<ans<<endl; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bosses.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &timer);
         ~~~~~^~~~~~~~~~~~~~
bosses.cpp:36: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...