제출 #943800

#제출 시각아이디문제언어결과실행 시간메모리
943800phoenix0423Bosses (BOI16_bosses)C++17
100 / 100
408 ms3668 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #pragma GCC optimize("Ofast") #define pb push_back #define eb emplace_back #define f first #define s second #define int long long #define lowbit(x) x&-x const int INF = 1e18; const int maxn = 1e5 + 5; const int N = 1e9 + 7; vector<int> adj[maxn]; int dep[maxn]; signed main(void){ fastio; int n; cin>>n; for(int i = 0; i < n; i++){ int d; cin>>d; for(int j = 0; j < d; j++){ int x; cin>>x; x--; adj[x].pb(i); } } int ans = INF; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) dep[j] = 0; dep[i] = 1; queue<int> q; q.push(i); int cnt = 0, cur = 0; while(!q.empty()){ int pos = q.front(); q.pop(); cnt++; cur += dep[pos]; for(auto x : adj[pos]){ if(dep[x]) continue; dep[x] = dep[pos] + 1; q.push(x); } } if(cnt < n) continue; ans = min(ans, cur); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...