답안 #388160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388160 2021-04-10T10:08:38 Z Sara Bosses (BOI16_bosses) C++17
100 / 100
753 ms 612 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define F first
#define S second
#define pb push_back
#define lc (ind << 1)
#define rc (lc | 1)
#define md ((b + e) >> 1)

const ll N = 5000 + 5;
const ll M = 1e6 + 5;
const ll LOG = 30;
const ll INF = 1e9 + 5;
const ll MOD = 1e9 + 7;

int n;
vector <int> g[N];
ll ans = INF * INF;
ll h[N];
queue <int> q;

inline ll bfs(int r){
    fill(h + 1, h + n + 1, INF);
    h[r] = 0;
    q.push(r);
    while (q.size()){
        int v = q.front();
        q.pop();
        for (int u : g[v]){
            if (h[v] + 1 < h[u]){
                h[u] = h[v] + 1;
                q.push(u);
            }
        }
    }
    ll sum = 0;
    for (int i = 1; i <= n; i ++){
        sum += h[i];
    }
    return sum + n;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int v = 1; v <= n; v ++){
        int m;
        cin >> m;
        for (int i = 0; i < m; i ++){
            int u;
            cin >> u;
            g[u].pb(v);
        }
    }
    for (int v = 1; v <= n; v ++){
        ans = min(ans, bfs(v));
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 5 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 151 ms 528 KB Output is correct
15 Correct 27 ms 460 KB Output is correct
16 Correct 606 ms 592 KB Output is correct
17 Correct 753 ms 612 KB Output is correct
18 Correct 753 ms 588 KB Output is correct