Submission #857777

#TimeUsernameProblemLanguageResultExecution timeMemory
857777qrnoBosses (BOI16_bosses)C++14
100 / 100
361 ms684 KiB
#include <cstdio> #include <vector> #include <array> #include <bitset> using namespace std; const int INF = 1e9; const int MAXN = 5e3; int best = INF; int N; array<vector<short>, MAXN> G; array<short, MAXN> val, q; signed main() { scanf("%d", &N); for (int i = 0; i < N; i++) { int K; scanf("%d", &K); while (K--) { int u; scanf("%d", &u); u--; G[u].push_back(i); } } for (int i = 0; i < N; i++) { int l = 0, r = -1; bitset<MAXN> vis; q[++r] = i; val[i] = 1; vis[i] = true; int done = 0, sum = 0; while (l <= r) { auto v = q[l++]; sum += val[v]; done++; for (auto u : G[v]) { if (!vis[u]) { q[++r] = u; val[u] = val[v]+1; vis[u] = true; } } } if (done < N) continue; best = min(best, sum); } printf("%d", best); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &N);
      |   ~~~~~^~~~~~~~~~
bosses.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     int K; scanf("%d", &K);
      |            ~~~~~^~~~~~~~~~
bosses.cpp:21:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |       int u; scanf("%d", &u); u--;
      |              ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...