Submission #857781

#TimeUsernameProblemLanguageResultExecution timeMemory
857781qrnoBosses (BOI16_bosses)C++17
100 / 100
365 ms856 KiB
#include <iostream> #include <vector> #include <array> #include <bitset> using namespace std; constexpr int INF = 1e9; constexpr int MAXN = 5e3; int best = INF; int N; array<vector<short>, MAXN> G; array<short, MAXN> val, q; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for (int i = 0; i < N; i++) { int K; cin >> K; while (K--) { int u; cin >> 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]) continue; q[++r] = u; val[u] = val[v]+1; vis[u] = true; } } best = (done < N) ? best : min(best, sum); } cout << best << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...