제출 #884349

#제출 시각아이디문제언어결과실행 시간메모리
884349vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pll array<ll, 2> #define int long long const int N = 5e3 + 4; const ll INF = 1LL << 62; int n, d[N], cnt[N]; bool vis[N]; vector<int> in[N]; ll bfs(int s) { queue<int> q; q.push(s); d[s] = 0; vis[s] = true; while (q.size() > 0) { int v = q.front(); q.pop(); for (int u : in[v]) { if (vis[u] == false) { vis[u] = true; d[u] = d[v] + 1; q.push(u); ++cnt[d[u]]; } } } pll ret = {0, 0}; for (int i = N - 1; i >= 0; --i) { ret[0] += cnt[i]; ret[1] += ret[0]; } return ret[1]; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { int k; cin >> k; while (k--) { int v; cin >> v; --v; in[v].pb(i); } } ll ans = INF; for (int i = 0; i < n; ++i) { ll res = bfs(i); bool seeAll = true; for (int j = 0; j < n; ++j) { seeAll &= vis[j]; vis[j] = false; } if (seeAll == true) { ans = min(ans, res); } } cout << ans + 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...