Submission #234000

#TimeUsernameProblemLanguageResultExecution timeMemory
234000DS007Bosses (BOI16_bosses)C++14
100 / 100
764 ms888 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 5000;
vector<int> adj[N];
bool explored[N];
int dist[N];
int n, c;

int solveTestCase(int test) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int k, v;
        cin >> k;
        while (k--) {
            cin >> v;
            adj[v - 1].push_back(i);
        }
    }

    int ans = 1e18;
    for (int i = 0; i < n; i++) {
        fill(dist, dist + N, 1e18);
        fill(explored, explored + N, false);
        int val = 1;
        dist[i] = 1;
        explored[i] = true;

        queue<int> q;
        q.push(i);
        c = 1;

        while (!q.empty()) {
            int v = q.front();
            q.pop();

            for (int j : adj[v]) {
                if (!explored[j])
                    dist[j] = dist[v] + 1, val += dist[j], q.push(j), explored[j] = true, c++;
            }
        }

        if (c == n)
            ans = min(ans, val);
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    //cin >> test;
    for (int i = 1; i <= test; i++)
        solveTestCase(i);
}

Compilation message (stderr)

bosses.cpp: In function 'long long int solveTestCase(long long int)':
bosses.cpp:49:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...