Submission #373924

#TimeUsernameProblemLanguageResultExecution timeMemory
373924Aryan_RainaBosses (BOI16_bosses)C++14
100 / 100
744 ms876 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ar array const int INF = 1e15; const int MOD = 1e9+7; const int MXN = 5005; vector<int> g[MXN]; int n; int bfs(int rt) { vector<int> d(n, -1); queue<int> q; q.push(rt); d[rt] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) if (d[v] == -1) { d[v] = d[u]+1; q.push(v); } } int ans = 0; for (int i = 0; i < n; i++) { if (d[i] == -1) return INF; ans += d[i]; } return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for (int i = 0; i < n; i++) { int x; cin>>x; while (x--) { int j; cin>>j; --j; g[j].push_back(i); } } int ans = INF; for (int i = 0; i < n; i++) ans = min(ans, bfs(i)); cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...