Submission #896129

# Submission time Handle Problem Language Result Execution time Memory
896129 2023-12-31T21:11:28 Z Andrey Bosses (BOI16_bosses) C++14
100 / 100
429 ms 796 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> haha[5001];

int n;

int calc(int s) {
    vector<int> ans(n+1,INT_MAX);
    ans[s] = 0;
    queue<int> idk;
    idk.push(s);
    while(!idk.empty()) {
        int a = idk.front();
        idk.pop();
        for(int v: haha[a]) {
            if(ans[v] > ans[a]+1) {
                ans[v] = ans[a]+1;
                idk.push(v);
            }
        }
    }
    int sb = 0;
    for(int i = 1; i <= n; i++) {
        if(ans[i] == INT_MAX) {
            return INT_MAX;
        }
        sb+=ans[i]+1;
    }
    return sb;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    int k,a;
    for(int i = 1; i <= n; i++) {
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> a;
            haha[a].push_back(i);
        }
    }
    int ans = INT_MAX;
    for(int i = 1; i <= n; i++) {
        ans = min(ans,calc(i));
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 75 ms 688 KB Output is correct
15 Correct 10 ms 600 KB Output is correct
16 Correct 402 ms 776 KB Output is correct
17 Correct 429 ms 796 KB Output is correct
18 Correct 427 ms 788 KB Output is correct