Submission #305561

#TimeUsernameProblemLanguageResultExecution timeMemory
305561vipghn2003Bosses (BOI16_bosses)C++14
100 / 100
784 ms760 KiB
#include<bits/stdc++.h> using namespace std; const int N=5005; int n,d[N]; vector<int>adj[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n; for(int i=1;i<=n;i++) { int m; cin>>m; while(m--) { int p; cin>>p; adj[p].push_back(i); } } long long res=1e18; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) d[j]=-1; queue<int>pq; d[i]=1; pq.push(i); while(!pq.empty()) { int u=pq.front(); pq.pop(); for(auto&v:adj[u]) { if(d[v]==-1) { d[v]=d[u]+1; pq.push(v); } } } bool check=true; for(int j=1;j<=n;j++) if(d[j]==-1) check=false; if(check) { long long cur=0; for(int j=1;j<=n;j++) cur+=d[j]; res=min(res,cur); } } cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...