제출 #206375

#제출 시각아이디문제언어결과실행 시간메모리
206375theStaticMindBosses (BOI16_bosses)C++14
0 / 100
6 ms504 KiB
#include<bits/stdc++.h> #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; vector<int> adj[5005]; vector<int> val(5005, INF); void bfs(int s){ val[s] = 1; queue<int> Q; Q.push(s); while(!Q.empty()){ int x = Q.front(); Q.pop(); for(auto y : adj[x]){ if(val[y] > val[x] + 1){ Q.push(y); val[y] = val[x] + 1; } } } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for(int i = 1; i <= n; i++){ int k; cin >> k; for(int j = 0; j < k; j++){ int x; cin >> x; adj[x].pb(i); } } int ans = INF; for(int i = 1; i <= n; i++){ bfs(i); int cnt = 0; for(int j = 1; j <= n; j++){ if(val[j] == INF)cnt++; else cnt += val[j]; } ans = min(ans, cnt); val = vector<int>(5005, INF); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...