Submission #857775

#TimeUsernameProblemLanguageResultExecution timeMemory
857775qrnoBosses (BOI16_bosses)C++17
100 / 100
388 ms684 KiB
#include <cstdio> #include <vector> #include <array> #include <queue> #include <bitset> 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<short>, MAXN> G; array<short, MAXN> val; 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++) { bitset<MAXN> vis; queue<int> Q; Q.push(i); val[i] = 1; vis[i] = true; int done = 0, sum = 0; while (!Q.empty()) { auto v = Q.front(); Q.pop(); sum += val[v]; done++; for (auto u : G[v]) { if (!vis[u]) { Q.push(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:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d", &N);
      |   ~~~~~^~~~~~~~~~
bosses.cpp:23:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     int K; scanf("%d", &K);
      |            ~~~~~^~~~~~~~~~
bosses.cpp:25:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |       int u; scanf("%d", &u); u--;
      |              ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...