Submission #866760

# Submission time Handle Problem Language Result Execution time Memory
866760 2023-10-27T02:49:00 Z 12345678 Bosses (BOI16_bosses) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=5e3+5;
int n, x, k, res, ans=INT_MAX, cnt, dp[nx];
vector<int> d[nx];
bool vs[nx];

void dfs(int u)
{
    vs[u]=1;
    cnt++;
    for (auto v:d[u]) if (!vs[v]) dfs(v), dp[u]+=dp[v];
    dp[u]++;
    res+=dp[u];
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>k;
        for (int j=0; j<k; j++) cin>>x, d[x].push_back(i);
    }
    for (int i=1; i<=n; i++)
    {
        cnt=res=0;
        for (int j=1; j<=n; j++) vs[j]=dp[j]=0;
        dfs(i);
        //cout<<i<<' '<<res<<'\n';
        if (cnt==n) ans=min(res, ans);
    }
    cout<<ans;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:31:45: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   31 |         for (int j=1; j<=n; j++) vs[j]=dp[j]=0;
      |                                        ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -