제출 #46550

#제출 시각아이디문제언어결과실행 시간메모리
46550ista2000Bosses (BOI16_bosses)C++17
0 / 100
1557 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int vector< vector<int> > v, g; vector<int> a; int n; void dfs(int u, int p) { a[u] = 1; for(int i: g[u]) if(i!=p) dfs(i, u), a[u]+=a[i]; } int bfs(int r) { queue< pair<int, int> > q; q.push(make_pair(r, r)); g.resize(n); a.resize(n, 0); vector<int> vis(n); vis[r] = 1; while(!q.empty()) { int cur = q.front().first; int curp = q.front().second; q.pop(); g[cur].push_back(curp); g[curp].push_back(cur); for(int i: v[cur]) { if(!vis[i]) { vis[i] = 1; q.push(make_pair(i, cur)); } } } bool done = true; for(int i = 0;i<n;i++) if(!vis[i]) done = false; if(!done)return INT_MAX; dfs(r, r); return accumulate(a.begin(), a.end(), 0ll); } #undef int int main() { #define int long long int ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; v.resize(n); for(int i = 0;i<n;i++) { int k; cin>>k; for(int j = 0;j<k;j++) { int x; cin>>x; x--; v[x].push_back(i); } } int ans = INT_MAX; for(int i = 0;i<n;i++) ans = min(ans, bfs(i)); cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...