Submission #1125136

#TimeUsernameProblemLanguageResultExecution timeMemory
1125136raul2008487Bosses (BOI16_bosses)C++20
100 / 100
397 ms5336 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define in insert #define fi first #define se second #define vl vector<ll> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int sz = 2e5 + 5; /// mind this const int MAX = 5005; const int BS = 61; const int mod = 1e9 + 7; const long long inf = (1e17); vl e[sz]; bool used[sz]; void solve(){ ll n, i, j, k, x, res = inf; cin >> n; for(i = 1; i <= n; i++){ cin >> k; while(k --){ cin >> x; e[x].pb(i); } } for(i = 1; i <= n; i++){ deque<array<ll, 2>> dq; used[i] = 1; ll ans = 0; dq.push_back({i, 1}); while(!dq.empty()){ ll cur = dq.back()[0], cd = dq.back()[1]; ans += cd; dq.pop_back(); for(auto to: e[cur]){ if(!used[to]){ dq.push_front({to, cd + 1}); used[to] = 1; } } } bool f = 1; for(j = 1; j <= n; j++){ f &= used[j]; used[j] = 0; } if(f){ res = min(res, ans); } } cout << res << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while(t--){ solve(); } } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...