제출 #975175

#제출 시각아이디문제언어결과실행 시간메모리
975175Error404Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define pb push_back #define pi pair<int,int> #define pl pair<ll,int> const int MAX = 5001; int color[MAX]; int dis[MAX]; vector<int>g[MAX]; int n; ll bfs(int u){ dis[u] =1; memset(color,0,sizeof(color)); queue<int>q; q.push(u); while(!q.empty()){ int from = q.front(); q.pop(); if(color[from]) continue; color[from]=1; for(int to: g[from]){ if(!color[to]){ dis[to]= dis[from]+1; q.push(to); } } } ll sum = 0; for(int i = 1; i <=n; i++) { sum+= dis[i]; if(!dis[i]) return LLONG_MAX; } // cout << u << " "<< sum << endl; return sum; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int temp, k; for(int i = 1; i <= n; i++){ cin >> temp; while(temp--){ cin >> k; g[k].pb(i); } } ll ans= LLONG_MAX; for(int i= 1; i <= n; i++){ ans = min(bfs(i),ans); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...