제출 #485802

#제출 시각아이디문제언어결과실행 시간메모리
485802radalBosses (BOI16_bosses)C++14
100 / 100
666 ms680 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("avx2,fma") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define mp make_pair #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef pair<int,int> pll; typedef pair<long double,long double> pld; const long long int N = 5e3+10,mod = 998244353,inf = 1e18,maxm = (1 << 24); inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int n,ll k){ int c = 1; while (k){ if (k&1) c = (1ll*c*n)%mod; n = (1ll*n*n)%mod; k >>= 1; } return c; } int sz[N],d[N]; vector<int> adj[N]; bool vis[N]; void bfs(int v){ d[v] = 0; vis[v] = 1; queue <int> q; q.push(v); while (!q.empty()){ int u = q.front(); q.pop(); for (int w : adj[u]){ if (!vis[w]){ q.push(w); d[w] = d[u]+1; vis[w] = 1; } } } } int main(){ ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; rep(i,1,n+1){ cin >> sz[i]; rep(j,0,sz[i]){ int u; cin >> u; adj[u].pb(i); } } ll ans = inf; rep(i,1,n+1){ bfs(i); ll cost = 0; bool f = 0; rep(i,1,n+1){ if (!vis[i]){ f = 1; continue; } cost += d[i]+1; vis[i] = 0; } if (!f) ans = min(ans,cost); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...