Submission #260286

#TimeUsernameProblemLanguageResultExecution timeMemory
260286arnold518Bosses (BOI16_bosses)C++14
100 / 100
710 ms888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 5000; int N; vector<int> adj[MAXN+10]; int dist[MAXN+10]; int main() { scanf("%d", &N); for(int i=1; i<=N; i++) { int p; scanf("%d", &p); while(p--) { int v; scanf("%d", &v); adj[v].push_back(i); } } ll ans=1e18; for(int i=1; i<=N; i++) { memset(dist, 0, sizeof(dist)); queue<int> Q; Q.push(i); dist[i]=1; while(!Q.empty()) { int now=Q.front(); Q.pop(); for(auto nxt : adj[now]) { if(dist[nxt]) continue; dist[nxt]=dist[now]+1; Q.push(nxt); } } ll t=0; for(int i=1; i<=N; i++) { if(dist[i]==0) t=1e18; t+=dist[i]; } ans=min(ans, t); } printf("%lld\n", ans); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bosses.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &p);
   ~~~~~^~~~~~~~~~
bosses.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &v);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...