제출 #927123

#제출 시각아이디문제언어결과실행 시간메모리
927123pccBosses (BOI16_bosses)C++14
100 / 100
413 ms816 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 5050; const ll inf = 1e9; ll dist[mxn]; queue<int> q; vector<int> paths[mxn]; int N,M; ll BFS(int s){ q.push(s); fill(dist,dist+N+1,inf); dist[s] = 1; q.push(s); while(!q.empty()){ auto now = q.front(); q.pop(); for(auto nxt:paths[now]){ if(dist[nxt]>dist[now]+1){ dist[nxt] = dist[now]+1; q.push(nxt); } } } return accumulate(dist+1,dist+N+1,0ll); } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; for(int i = 1;i<=N;i++){ int k; cin>>k; while(k--){ int tmp; cin>>tmp; paths[tmp].push_back(i); } } ll ans = inf*inf; for(int i = 1;i<=N;i++)ans = min(ans,BFS(i)); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...