제출 #1044109

#제출 시각아이디문제언어결과실행 시간메모리
1044109inkvizytorBosses (BOI16_bosses)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> g (n+1);
    for (int i = 1; i < n+1; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            g[x].push_back(i);
        }
    }
    vector<bool> odw (n+1, 0);
    vector<int> d (n+1, 0);
    int score = 0, mini = 1000000000;
    for (int i = 1; i < n+1; i++) {
        odw[i] = 1;
        d[i] = 1;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int u : g[v]) {
                if (!odw[u]) {
                    odw[u] = 1;
                    d[u] = d[v]+1;
                    q.push(u);
                }
            }
        }
        score = 0;
        for (int j = 1; j < n+1; j++) {
            score += d[j];
            odw[j] = 0;
            d[j] = 0;
        }
        for (int i = 1; i < n+1; i++) {
            if (!odw[i]) {
                score = 1000000000;
            }
        }
        mini = min(mini, score);
    }
    cout << mini << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...