제출 #951875

#제출 시각아이디문제언어결과실행 시간메모리
951875MohamedAhmed04Bosses (BOI16_bosses)C++14
100 / 100
424 ms848 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 5000 + 10 ; int n ; vector< vector<int> >adj(MAX) ; int dep[MAX] , vis[MAX] ; int solve(int boss) { for(int i = 1 ; i <= n ; ++i) vis[i] = 0 ; int cnt = 0 , sum = 0 ; queue<int>q ; q.push(boss) ; dep[boss] = 1 , vis[boss] = 1 ; while(!q.empty()) { int node = q.front() ; q.pop() ; cnt++ , sum += dep[node] ; for(auto &child : adj[node]) { if(!vis[child]) { vis[child] = 1 ; dep[child] = dep[node] + 1 ; q.push(child) ; } } } if(cnt != n) sum = 2e9 ; return sum ; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n ; for(int i = 1 ; i <= n ; ++i) { int sz ; cin>>sz ; while(sz--) { int node ; cin>>node ; adj[node].push_back(i) ; } } int ans = 1e9 ; for(int i = 1 ; i <= n ; ++i) ans = min(ans , solve(i)) ; return cout<<ans<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...