Submission #350575

#TimeUsernameProblemLanguageResultExecution timeMemory
350575Hossein29Bosses (BOI16_bosses)C++14
0 / 100
1 ms620 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 5e3+10; const int inf = 1e18; int n,ans,sum; bool check; vector<int>G[maxn]; vector<int>H[maxn]; bool marked[maxn]; int val[maxn]; //int lev[maxn]; void bfs(int v){ marked[v] = true; queue<int>q; q.push(v); // lev[v] = 0; while(!q.empty()){ int p = q.front(); q.pop(); H[p].clear(); for(int b : G[p]){ if(marked[b]) continue; // lev[b] = lev[p] + 1; marked[b] = true; q.push(b); H[p].push_back(b); } } } void dfs(int v){ int s = 0; for(int b : H[v]){ dfs(b); s += val[b]; } val[v] = s + 1; sum += val[v]; if(ans <= sum){ check = false; return; } } int32_t main(){ ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0); //////////////////////////////////////////////// ans = inf; sum = 0; cin >> n; for(int i = 0;i<n;i++){ int x; cin >> x; for(int j = 0;j<x;j++){ int y; cin >> y; G[y].push_back(i+1); } } for(int i = 0;i<n;i++){ bfs(i+1); fill(marked,marked+n+1,false); check = true; sum = 0; dfs(i+1); if(check == true){ ans = min(ans,sum); } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...