# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
509441 | 2022-01-14T05:46:17 Z | ac2hu | Bosses (BOI16_bosses) | C++14 | 0 ms | 332 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Incorrect | 0 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Incorrect | 0 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Incorrect | 0 ms | 332 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |