Submission #695227

#TimeUsernameProblemLanguageResultExecution timeMemory
695227AbitoBosses (BOI16_bosses)C++14
100 / 100
720 ms748 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second #define int long long #define ep insert const int N=5005; int n,p[N],dp[N]; vector<int> adj[N]; vector<int> q; void bfs(int node){ q.pb(node); for (int i=0;i<q.size();i++){ for (auto u:adj[q[i]]){ if (p[u]) continue; p[u]=q[i]; q.pb(u); } }return; } void getans(){ reverse(q.begin(),q.end()); for (int i=0;i<q.size()-1;i++) dp[p[q[i]]]+=dp[q[i]]; return; } int32_t main(){ cin>>n; for (int i=1;i<=n;i++){ int x;cin>>x; while (x--){ int y;cin>>y; adj[y].pb(i); } } int ans=INT_MAX; for (int i=1;i<=n;i++){ q.clear(); for (int i=1;i<=n;i++){ p[i]=0; dp[i]=1; }p[i]=-1; bfs(i); if (q.size()<n) continue; getans(); int s=0; for (int i=1;i<=n;i++) s+=dp[i]; ans=min(ans,s); }cout<<ans<<endl; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'void bfs(long long int)':
bosses.cpp:14:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i=0;i<q.size();i++){
      |                  ~^~~~~~~~~
bosses.cpp: In function 'void getans()':
bosses.cpp:24:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i=0;i<q.size()-1;i++) dp[p[q[i]]]+=dp[q[i]];
      |                  ~^~~~~~~~~~~
bosses.cpp: In function 'int32_t main()':
bosses.cpp:44:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   44 |         if (q.size()<n) continue;
      |             ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...