Submission #866762

#TimeUsernameProblemLanguageResultExecution timeMemory
86676212345678Bosses (BOI16_bosses)C++17
100 / 100
411 ms852 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]; 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=0; for (int j=1; j<=n; j++) vs[j]=dp[j]=0; queue<int> q; q.push(i); vs[i]=dp[i]=res=1; while (!q.empty()) { auto u=q.front(); cnt++; q.pop(); for (auto v:d[u]) if (!vs[v]) dp[v]=dp[u]+1, res+=dp[v], vs[v]=1, q.push(v); } if (cnt==n) ans=min(ans, res); } cout<<ans; }

Compilation message (stderr)

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