Submission #634750

# Submission time Handle Problem Language Result Execution time Memory
634750 2022-08-24T20:10:19 Z tvladm2009 Bosses (BOI16_bosses) C++14
0 / 100
1 ms 468 KB
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#define int long long

using namespace std;

const int MAX_N = 5 * 1e3;
const int INF = (1LL << 60);
int dist[MAX_N + 1];
bool viz[MAX_N + 1];
vector<int> g[MAX_N + 1];
int n;

int bfs(int start) {
    memset(dist, 0, sizeof(dist));
    memset(viz, 0, sizeof(viz));
    queue<int> q;
    q.push(start);
    dist[start] = 1;
    int cost = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        viz[u] = true;
        for (int v : g[u]) {
            if (!viz[v]) {
                dist[v] = dist[u] + 1;
                cost += dist[v];
                q.push(v);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!viz[i]) {
            return INF;
        }
    }
    return cost;
}

signed main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++) {
            int x;
            cin >> x;
            g[x].push_back(i);
        }
    }
    int answer = INF;
    for (int i = 1; i <= n; i++) {
        answer = min(answer, bfs(i));
    }
    cout << answer;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -