# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546738 | Jomnoi | Bosses (BOI16_bosses) | C++17 | 1 ms | 440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int MAX_N = 5e3 + 10;
const int INF = 1e9 + 7;
int sum;
vector <int> adj[MAX_N];
bitset <MAX_N> visited;
int dfs(int u) {
int res = 0;
for(auto v : adj[u]) {
if(visited[v] == false) {
visited[v] = true;
res += dfs(v);
}
}
res++;
sum += res;
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
int k;
cin >> k;
while(k--) {
int p;
cin >> p;
adj[p].push_back(i);
}
}
int ans = INF;
for(int i = 1; i <= n; i++) {
visited = 0;
sum = 0;
visited[i] = true;
dfs(i);
if(visited.count() == n) {
ans = min(ans, sum);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |