# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546745 | Jomnoi | Bosses (BOI16_bosses) | C++17 | 0 ms | 340 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 long long INF = 1e18 + 7;
vector <int> adj[MAX_N];
bitset <MAX_N> visited;
long long dfs(int u, int s) {
long long sum = s;
for(auto v : adj[u]) {
if(visited[v] == false) {
visited[v] = true;
sum += dfs(v, s + 1);
}
}
return sum;
}
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);
}
}
long long ans = INF;
for(int i = 1; i <= n; i++) {
visited = 0;
visited[i] = true;
long long sum = dfs(i, 1);
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... |