답안 #884277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884277 2023-12-07T05:49:45 Z vjudge1 Bosses (BOI16_bosses) C++17
0 / 100
0 ms 856 KB
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 5e3 + 10, INF = 1e9;

int n, ans = INF;
vector<int> G[N];

void bfs(int v) {
    queue<int> q;
    vector<int> h(N, INF), H(N, 0);
    int res = 0, ps = 0;
    h[v] = 0;
    q.push(v);
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto e : G[u])
            if (h[u] + 1 < h[e]) {
                h[e] = h[u] + 1;
                q.push(e);
            }
    }
    for (int i = 0; i < n; i++) {
        if (h[i] == INF) continue;
        H[h[i]]++;
    }
    for (int i = n; i >= 0; i--)
        ps += H[i], res += ps;
    ans = min(ans, res);
}

signed main() {
    ios:: sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int m, x;
        cin >> m;
        for (int j = 0; j < m; j++) {
            cin >> x;
            G[--x].pb(i);
        }
    }
    for (int i = 0; i < n; i++) bfs(i);
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -