제출 #374040

#제출 시각아이디문제언어결과실행 시간메모리
374040ritul_kr_singhBosses (BOI16_bosses)C++17
67 / 100
1573 ms1016 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long #define sp << " " << #define nl << "\n" vector<vector<int>> g0, g1; vector<bool> vis; ll totalSum; ll dfs(int u){ ll res = 1; for(int v : g1[u]) res += dfs(v); totalSum += res; return res; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; g0.resize(n); g1.resize(n); vis.resize(n); for(int i=0; i<n; ++i){ int k; cin >> k; for(int j=0; j<k; ++j){ int x; cin >> x; g0[x-1].push_back(i); } } ll ans = 1e18; for(int root=0; root<n; ++root){ for(int i=0; i<n; ++i) vis[i] = false; for(int i=0; i<n; ++i) g1[i].clear(); queue<int> q; q.push(root); vis[root] = true; while(!q.empty()){ int u = q.front(); q.pop(); for(int v : g0[u]){ if(!vis[v]){ vis[v] = true; q.emplace(v); g1[u].push_back(v); } } } bool ok = true; for(int i=0; i<n; ++i){ if(!vis[i]) ok = false; } if(!ok) continue; totalSum = 0; dfs(root); ans = min(ans, totalSum); } cout << ans nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...