Submission #541845

#TimeUsernameProblemLanguageResultExecution timeMemory
541845TheTrapperBosses (BOI16_bosses)C++14
100 / 100
700 ms724 KiB
#include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using pll=pair<ll,ll>; using vll=vector<ll>; using vpl=vector<pll>; using vstr=vector<string>; using sll=set<ll>; using spl=set<pll>; ll INF=1e18; #define PI 3.14159265 ll MOD=1e9+7; ll n=0; vll v[5005]; bool visited[5005]; ll dist[5005]; queue<ll>q; ll minimum=INF; ll BFS(ll x) { dist[x]=1; q.push(x); visited[x]=true; while(!q.empty()) { ll y=q.front(); q.pop(); for(auto e:v[y]) { if(!visited[e]) { q.push(e); visited[e]=true; dist[e]=dist[y]+1; } } } ll s=0; for(ll i=1;i<=n;i++) { if(!visited[i]) { return INF; } s += dist[i]; } return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(ll i=0;i<n;i++) { ll x; cin >> x; for(ll j=0;j<x;j++) { ll e; cin >> e; v[e].push_back(i+1); } } for(ll i=1;i<=n;i++) { ll b=BFS(i); minimum=min(minimum,b); memset(visited,false,sizeof(visited)); } cout << minimum << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...