Submission #218097

#TimeUsernameProblemLanguageResultExecution timeMemory
218097Alexa2001Bosses (BOI16_bosses)C++17
0 / 100
11 ms512 KiB
#include <bits/stdc++.h> using namespace std; ///10:45 typedef long long ll; const int Nmax = 5005; vector<int> v[Nmax]; int n, d[Nmax]; ll solve(int start) { queue<int> q; memset(d, 0, sizeof(d)); q.push(start); d[start] = 1; ll ans = 1; while(q.size()) { int node = q.front(); q.pop(); for(auto it : v[node]) if(!d[it]) { d[it] = d[node] + 1; ans += d[it]; q.push(it); } } return ans; } int main() { // freopen("input", "r", stdin); cin.sync_with_stdio(false); cin.tie(0); cin >> n; int i; for(i=1; i<=n; ++i) { int nr; cin >> nr; while(nr--) { int x; cin >> x; v[x].push_back(i); } } ll ans = LLONG_MAX; for(i=1; i<=n; ++i) ans = min(ans, solve(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...