Submission #858043

#TimeUsernameProblemLanguageResultExecution timeMemory
858043vjudge1Bosses (BOI16_bosses)C++17
100 / 100
398 ms860 KiB
//In His Name #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef pair<long long, int> pli; typedef pair<long long, long long> pll; #define ll long long #define int ll #define F first #define S second #define pb push_back #define bug(x) cout << "Ah shit , here we go again : " << x <<endl #define all(x) x.begin() , x.end() #define ceil(x,y) x/y + min(1,x%y); const int maxn = 5000 + 15, MOD = 1e9 + 7; const ll INF = 1e18; int n , h[maxn] , ans = INF; vector<int> adj[maxn]; bool mark[maxn]; void Bfs(int i){ memset(mark , false , sizeof mark); queue<int> q; q.push(i); h[i] = 1; mark[i] = true; int sum = 1; while(!q.empty()){ int v = q.front(); q.pop(); for(int u : adj[v]){ if(!mark[u]){ q.push(u); mark[u] = true; h[u] = h[v]+1; sum += h[u]; } } } for(int j = 1 ; j <= n ; j++) if(!mark[j]) return; ans = min(sum , ans); } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1 ; i <= n ; i++){ int j; cin >> j; for(int l = 1 ; l <= j ; l++){ int x; cin >> x; adj[x].pb(i); } } for(int i = 1 ; i <= n ; i++) Bfs(i); cout << ans; }

Compilation message (stderr)

bosses.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...