Submission #1017073

#TimeUsernameProblemLanguageResultExecution timeMemory
1017073ivazivaBosses (BOI16_bosses)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 5010 long long n; vector<long long> adj[MAXN]; long long dist[MAXN]; queue<long long> bfsq; void bfs(long long pret) { for (long long i=1;i<=n;i++) dist[i]=LLONG_MAX; dist[pret]=1;bfsq.push(pret); while (bfsq.empty()==false) { long long node=bfsq.front(); bfsq.pop(); for (long long sled:adj[node]) { if (dist[sled]!=LLONG_MAX) continue; dist[sled]=dist[node]+1; bfsq.push(sled); } } } int main() { cin>>n; for (long long i=1;i<=n;i++) { long long s;cin>>s; for (long long j=0;j<s;j++) { long long x;cin>>x; adj[x].push_back(i); } } long long ans=LLONG_MAX; for (long long i=1;i<=n;i++) { bfs(i);long long sol=0; for (long long j=1;j<=n;j++) sol+=dist[j]; ans=min(ans,sol); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...