# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546746 | Jomnoi | Bosses (BOI16_bosses) | C++17 | 743 ms | 648 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;
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;
long long sum = 0;
visited[i] = true;
queue <pair <int, int>> q;
q.emplace(i, 1);
while(!q.empty()) {
auto [u, c] = q.front();
q.pop();
sum += c;
for(auto v : adj[u]) {
if(visited[v] == false) {
visited[v] = true;
q.emplace(v, c + 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... |