# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1050226 | manhlinh1501 | Bosses (BOI16_bosses) | C++17 | 514 ms | 1220 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>
using namespace std;
using i64 = long long;
const i64 oo64 = 2e18;
const int MAXN = 5e3 + 5;
int N;
vector<int> adj[MAXN];
vector<int> g[MAXN];
int dist[MAXN];
i64 ans = oo64;
void BFS(int r) {
for(int i = 1; i <= N; i++) {
g[i].clear();
dist[i] = N + 1;
}
queue<int> Q;
Q.emplace(r);
dist[r] = 1;
while(!Q.empty()) {
int u = Q.front();
Q.pop();
for(int v : adj[u]) {
if(dist[v] > dist[u] + 1) {
g[u].emplace_back(v);
dist[v] = dist[u] + 1;
Q.emplace(v);
}
}
}
i64 res = 0;
for(int i = 1; i <= N; i++) {
if(dist[i] > N) return;
res += dist[i];
}
ans = min(ans, res);
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++) {
int sz = 0;
cin >> sz;
for(int j = 1; j <= sz; j++) {
int x = 0;
cin >> x;
adj[x].emplace_back(i);
}
}
for(int i = 1; i <= N; i++) BFS(i);
cout << ans;
return (0 ^ 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... |