제출 #388236

#제출 시각아이디문제언어결과실행 시간메모리
388236soroushBosses (BOI16_bosses)C++17
100 / 100
1182 ms908 KiB
//* //#pragma GCC optimize("O2") #pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("avx,avx2,sse,sse2,fma") //*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int , int> pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 5010; const ll mod = 1e9+7; const ld PI = acos((ld)-1); #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define ms(x , y) memset(x , y , sizeof x) ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} int n; vector < int > in[maxn]; bool mark[maxn]; int sz[maxn]; int q[maxn] , l , r; vector < int > adj[maxn]; void dfs(int v){ sz[v] = 1; for(auto u : adj[v]) dfs(u) , sz[v] += sz[u]; } int solve(int v){ l = r = 0; ms(mark , 0); for(int i = 1 ; i <= n ; i ++)adj[i].clear(); q[r++] = v; mark[v] = 1; int cnt = 1; while(l < r){ int v = q[l++]; for(auto u : in[v])if(!mark[u]) mark[u] = 1, cnt++ , q[r++] = u , adj[v].pb(u); } if(cnt ^ n)return 1e9; dfs(v); int ans = 0; for(int i = 1 ; i <= n ; i ++)ans += sz[i]; return ans; } int32_t main(){ migmig; cin >> n; for(int i = 1 ; i <= n ; i ++){ int k; cin >> k; for(int j = 0 ; j < k ; j ++){ int v; cin >> v; in[v].pb(i); } } //in-tree , sigma sz[v] min she int ans = 1e9; for(int i = 1 ; i <= min(n, 2500) ; i ++) ans = min(ans , solve(i)); for(int i = n ; i >= 3500 ; i --) ans = min(ans , solve(i)); cout << ans; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...