Submission #866761

#TimeUsernameProblemLanguageResultExecution timeMemory
86676112345678Bosses (BOI16_bosses)C++17
100 / 100
822 ms1112 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], tmp[nx]; bool vs[nx]; void dfs(int u) { for (auto v:tmp[u]) 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, tmp[j].clear(); queue<int> q; q.push(i); vs[i]=1; while (!q.empty()) { auto u=q.front(); cnt++; //printf("here %d %d\n", u, cnt); q.pop(); for (auto v:d[u]) if (!vs[v]) tmp[u].push_back(v), vs[v]=1, q.push(v); } if (cnt==n) { dfs(i); ans=min(ans, res); } } cout<<ans; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:29:45: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   29 |         for (int j=1; j<=n; j++) vs[j]=dp[j]=0, tmp[j].clear();
      |                                        ~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...