Submission #532224

#TimeUsernameProblemLanguageResultExecution timeMemory
532224andecaandeciBosses (BOI16_bosses)C++17
100 / 100
770 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second const int maxn = 5e3+1; int minum = 1e9; int main(){ int n; scanf("%d",&n); vector<int> adj[maxn]; for(int i=1;i<=n;i++){ int k; scanf("%d",&k); for(int j=0;j<k;j++){ int x; scanf("%d",&x); adj[x].pb(i); } } queue<int> q; int temp = 0; for(int i=1;i<=n;i++){ if(adj[i].empty()) continue; vector<bool> vis(n+1); q.push(i); vis[i] = 1; int node = 0,cnt = 1,ans = n; while(!q.empty()){ temp = q.front(); q.pop(); node++; for(auto it : adj[temp]){ if(!vis[it]){ vis[it] = 1; q.push(it); } } cnt--; if(cnt == 0){ ans += (n - node); cnt = (int) q.size(); } } if(node == n){ minum = min(minum,ans); } } printf("%d",minum); return 0; }

Compilation message (stderr)

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