Submission #30905

#TimeUsernameProblemLanguageResultExecution timeMemory
30905NavickBosses (BOI16_bosses)C++14
100 / 100
533 ms2312 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back using namespace std; typedef long long ll; typedef long double ld; const int N = 5100, INF = 1e9; int dis[N], que[N], st, en, n; vector<int> adj[N]; inline int solve(int s){ st = en = 0; que[en++] = s; for(int i=1; i<=n; i++) dis[i] = INF; dis[s] = 0; while(en - st){ int v = que[st++]; for(auto u : adj[v]) if(dis[u] == INF){ dis[u] = dis[v] + 1; que[en++] = u; } } int res = n; for(int i=1; i<=n; i++){ if(dis[i] == INF)return INF; else res += dis[i]; } return res; } int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ int k; scanf("%d", &k); while(k--){ int v; scanf("%d", &v); adj[v].pb(i); } } int ans = INF; for(int i=1; i<=n; i++){ ans = min(ans, solve(i)); } printf("%d\n", ans); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:41:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
bosses.cpp:43:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int k; scanf("%d", &k);
                         ^
bosses.cpp:45:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int v; scanf("%d", &v);
                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...