제출 #641781

#제출 시각아이디문제언어결과실행 시간메모리
641781Ronin13Bosses (BOI16_bosses)C++14
100 / 100
820 ms668 KiB
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int NMAX = 5001; vector <vector <ll> >g(NMAX); ll ans = 0; int ansi; ll mn = 1e9; vector <bool> used(NMAX); vector <ll> d(NMAX); int n; void bfs(int x){ used[x] = true; d[x] = 1; queue <int> q; q.push(x); while(!q.empty()){ int v = q.front(); q.pop(); for(int to : g[v]){ if(used[to]) continue; q.push(to); used[to] = true; d[to] = d[v] + 1; } } for(int i = 1; i <= n; i++){ if(!used[i]){ ans = 1e9; break; } else ans += d[i]; } } int main(){ cin >> n; for(int i = 1; i <= n; i++){ int x; cin >> x; for(int j = 1; j <= x; j++) { int y; cin >> y; g[y].pb(i); } } for(int i = 1; i <= n; i++){ bfs(i); mn = min(ans, mn); for(int j = 1; j <= n; j++){ used[j] = false; d[j] = 0; } ans = 0; } cout << mn; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...