답안 #857865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857865 2023-10-07T06:02:14 Z vjudge1 Bosses (BOI16_bosses) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
const long long int INF = 1e18;
int n, mark[maxn], val[maxn];
vector<int> ad[maxn];

void dfs(int v) {
    mark[v] = 1;
    for (int u: ad[v]) {
        if (!mark[u]) {
            dfs(u);
            val[v] += val[u];
        }
    }
    val[v]++;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        int t;
        cin >> t;
        for (int j = 1; j <= t; j++) {
            int x;
            cin >> x;
            ad[x].push_back(i);
        }
    }
    long long int ans = INF;
    for (int i = 1; i <= n; i++) {
        bool tf = true;
        dfs(i);
        long long int sum = 0;
        for (int j = 1; j <= n; j++) {
            sum += val[j];
            if(val[j] == 0){
                tf = false;
                break;
            }
        }
        if (sum < ans and tf)
            ans = sum;
        memset(val, 0, sizeof val);
        memset(mark, 0, sizeof mark);
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -