# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533205 | christinelynn | Bosses (BOI16_bosses) | C++17 | 1 ms | 460 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;
#define ll long long
ll n;
vector<ll> adj[5005];
ll dist[5005][5005];
bool vis[5005][5005];
ll bfs(ll x) {
queue <ll> q;
q.push(x);
ll sum = 1;
dist[x][x] = 1;
ll mx = 0;
vis[x][x] = true;
while(!q.empty()) {
ll cur = q.front();
q.pop();
for(ll i = 0; i < adj[cur].size(); i++) {
ll next = adj[cur][i];
if (!vis[next][x]) {
vis[next][x] = true;
dist[next][x] = dist[cur][x] + 1;
sum += dist[next][x];
mx = max(mx, dist[next][x]);
q.push(next);
}
}
}
return sum;
}
int main() {
cin >> n;
for(ll i = 1; i <= n; i++) {
ll k;
cin >> k;
for(ll j = 0; j < k; j++) {
ll next;
cin >> next;
adj[next].push_back(i);
}
}
ll mn = LLONG_MAX;
for(ll i = 1; i <= n; i++) {
mn = min(mn, bfs(i));
}
cout << mn << endl;
}
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... |