Submission #290694

#TimeUsernameProblemLanguageResultExecution timeMemory
290694davooddkareshkiBosses (BOI16_bosses)C++17
0 / 100
1 ms512 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define pii pair<int,int> #define mpr make_pair typedef long long ll; const int maxn = 5010; const int mod = 1e9+7; const int inf = 1e9+10; int n, m; vector<int> g[maxn]; bool mark[maxn]; int dis[maxn]; int bfs(int s) { memset(mark, 0, sizeof mark); memset(dis, 0, sizeof dis); queue<int> q; q.push(s); dis[s] = 1; mark[s] = 1; int ans = 0; while(q.size()) { int v = q.front(); q.pop(); ans += dis[v]; for(auto u : g[v]) if(!mark[u]) { mark[u] = 1; dis[u] = dis[v] + 1; q.push(u); } } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>> n; for(int i = 1, sz; i <= n; i++) { cin>> sz; while(sz--) { int v; cin>> v; g[v].push_back(i); } } int ans = inf; for(int i = 1; i <= n; i++) ans = min(ans,bfs(i)); cout<< ans; } /* 4 1 4 3 1 3 4 2 1 2 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...