제출 #924996

#제출 시각아이디문제언어결과실행 시간메모리
924996NintsiChkhaidzeBosses (BOI16_bosses)C++17
67 / 100
132 ms604 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define pii pair <int,int> #define left (h<<1),l,(l + r)/2 #define right ((h<<1)|1),(l + r)/2 + 1,r #define int ll using namespace std; const int N = 5000 + 3; int vis[N],dep[N],cnt[N]; vector <int> v[N]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++){ int k; cin>>k; for (int j= 1; j <= k; j++){ int x; cin>>x; v[x].pb(i); } } int ans = 1e18; for (int root = 1; root <= n; root++){ for (int i = 1;i <= n; i++) dep[i] = 0,cnt[i] = 0; queue <int> q; q.push(root); dep[root] = 1; while(q.size()){ int x = q.front(); q.pop(); for (int to: v[x]){ if (!dep[to]) { dep[to] = dep[x] + 1; q.push(to); } } } for(int i=1;i<=n;i++) cnt[dep[i]]++; int sum = n,cur = n; for (int i = 1; i <= n; i++){ cur -= cnt[i]; sum += cur; } ans=min(ans,sum); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...