Submission #595811

#TimeUsernameProblemLanguageResultExecution timeMemory
595811BelphegorBosses (BOI16_bosses)C++14
100 / 100
648 ms656 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; vector<int>tree[5005]; int depth[5005]; int f(int root){ memset(depth,0,sizeof(depth)); depth[root] = 1; queue<int>q; q.push(root); int ret = 0; while(!q.empty()){ int cur = q.front(); q.pop(); ret+=depth[cur]; for(int nxt:tree[cur]){ if(depth[nxt]) continue; depth[nxt] = depth[cur]+1; q.push(nxt); } } for(int i=1; i<=n; i++) if(!depth[i]) return INT32_MAX; return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(int i=1; i<=n; i++){ int k; cin>>k; for(int j=0; j<k; j++){ int x; cin>>x; tree[x].emplace_back(i); } } int ans = INT32_MAX; for(int i=1; i<=n; i++) ans = min(ans,f(i)); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...