Submission #1074800

#TimeUsernameProblemLanguageResultExecution timeMemory
1074800IcelastBosses (BOI16_bosses)C++17
100 / 100
717 ms1500 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ int n; cin >> n; vector<int> a(n+1); vector<vector<int>> boss(n+1), canboss(n+1), canboss2; for(int i = 1; i <= n; i++){ cin >> a[i]; for(int j = 1; j <= a[i]; j++){ int v; cin >> v; boss[i].push_back(v); canboss[v].push_back(i); } } canboss2 = canboss; vector<vector<int>> adj(n+1); vector<int> cur, t, vis(n+1, 0); ll ans = INF; for(int root = 1; root <= n; root++){ canboss = canboss2; ll res = 0; ll left = n-1; for(int i = 1; i <= n; i++) vis[i] = 0; vis[root] = 1; cur.clear(); cur.push_back(root); for(ll d = 1; d <= n; d++){ if(cur.empty()) break; t.clear(); res += d*cur.size(); for(int i : cur){ while(!canboss[i].empty()){ int j = canboss[i].back(); canboss[i].pop_back(); if(vis[j]) continue; vis[j] = 1; t.push_back(j); left--; } } cur = t; } if(left > 0) res = INF; ans = min(ans, res); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...