Submission #509441

#TimeUsernameProblemLanguageResultExecution timeMemory
509441ac2huBosses (BOI16_bosses)C++14
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; int n; vector<int> adj[N]; int visited[N]; int lev[N]; int dfs(int i){ if(!visited[i]){ int ans = 0; visited[i] = true; for(int e : adj[i]){ // cout << 'd' << " " << e << "\n"; if(!visited[e]){ ans += dfs(e); } } lev[i] = ans + 1; return lev[i]; } } signed main(){ iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); cin >> n; for(int i = 0;i<n;i++){ int c;cin >> c; for(int j = 0;j<c;j++){ int temp;cin >> temp; temp --; adj[i].push_back(temp); } } int ans = 1e9; for(int i = 0;i<n;i++){ // This will the root of the tree for(int i = 0;i<n;i++){ visited[i] =false; lev[i] = -1; } dfs(i); int temp = 0; for(int i = 0;i<n;i++){ temp += lev[i]; if(!visited[i]){ // cout << i << "\n"; goto next; } } ans = min(ans,temp); next: continue; } cout << ans << "\n"; }

Compilation message (stderr)

bosses.cpp: In function 'int dfs(int)':
bosses.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...