Submission #857772

#TimeUsernameProblemLanguageResultExecution timeMemory
857772qrnoBosses (BOI16_bosses)C++11
100 / 100
411 ms848 KiB
#include <cstdio> #include <vector> #include <array> #include <queue> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") const int INF = 1e9; const int MAXN = 5e3; int best = INF; int N; array<vector<int>, MAXN> G; array<int, MAXN> val, last; 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++) { queue<int> Q; Q.push(i); val[i] = 1; last[i] = i; int done = 0, sum = 0; while (!Q.empty()) { auto v = Q.front(); Q.pop(); sum += val[v]; done++; for (auto u : G[v]) { if (last[u] != i) { Q.push(u); val[u] = val[v]+1; last[u] = i; } } } if (done < N) continue; best = min(best, sum); } printf("%d", best); }

Compilation message (stderr)

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