Submission #877510

#TimeUsernameProblemLanguageResultExecution timeMemory
877510Beerus13Bosses (BOI16_bosses)C++14
100 / 100
408 ms852 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 5e3 + 5; int n; vector<int> g[N]; int dp[N]; int bfs(int u) { queue<int> q; memset(dp, 0, sizeof(dp)); dp[u] = 1; q.push(u); while(q.size()) { int s = q.front(); q.pop(); for(int t : g[s]) if(dp[t] == 0) { dp[t] = dp[s] + 1; q.push(t); } } int res = 0; for(int i = 1; i <= n; ++i) { res += dp[i]; if(dp[i] == 0) return 1e9; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; ++i) { int k, x; cin >> k; while(k--) { cin >> x; g[x].push_back(i); } } int ans = 1e9; for(int i = 1; i <= n; ++i) ans = min(ans, bfs(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...