Submission #866760

#TimeUsernameProblemLanguageResultExecution timeMemory
86676012345678Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...