Submission #533444

#TimeUsernameProblemLanguageResultExecution timeMemory
533444christinelynnBosses (BOI16_bosses)C++17
100 / 100
616 ms656 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; int main(){ ll n; cin>>n; vector<ll> adj[n+7]; ll k,l; for(int i=1;i<=n;i++){ cin>>k; for(int j=1;j<=k;j++){ cin>>l; adj[l].pb(i); } } ll ans=1e12; for(int i=1;i<=n;i++){ ll dist[n+7]; memset(dist,0,sizeof(dist)); queue<ll> q; q.push(i); dist[i]=1; while(!q.empty()){ ll y=q.front(); q.pop(); for(auto x:adj[y]){ if(!dist[x]){ dist[x]=dist[y]+1; q.push(x); } } } bool np=false; ll sum=0; for(int j=1;j<=n;j++){ if(!dist[j]){ np=true; } else{ sum+=dist[j]; } } if(!np){ ans=min(ans,sum); } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...