Submission #400926

#TimeUsernameProblemLanguageResultExecution timeMemory
400926Pichon5Bosses (BOI16_bosses)C++17
100 / 100
980 ms772 KiB
#include <bits/stdc++.h> #define pb push_back #define vi vector<int> #define F first #define ll long long #define S second #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; vector<vi>G,G2; ll suma[5001]; ll sum=0; vector<bool>vis; void dfs(int nodo, int p){ suma[nodo]=1; for(int i=0;i<G2[nodo].size();i++){ int to=G2[nodo][i]; if(to==p)continue; dfs(to,nodo); suma[nodo]+=suma[to]; } sum+=suma[nodo]; } int main() { fast int n,x,k; cin>>n; G.resize(n+1); for(int i=1;i<=n;i++){ cin>>k; for(int l=0;l<k;l++){ cin>>x; G[x].pb(i); } } ll res=1e16; for(int i=1;i<=n;i++){ G2.assign(n+1,vi()); vis.assign(n+1,false); queue<int>q; int cant=0; q.push(i); vis[i]=1; int dp[n+1]; for(int i=1;i<=n;i++)dp[i]=1; sum=0; while(!q.empty()){ int nodo=q.front(); q.pop(); sum+=dp[nodo]; cant++; for(int l=0;l<G[nodo].size();l++){ int to=G[nodo][l]; if(!vis[to]){ dp[to]+=dp[nodo]; //G2[nodo].pb(to); //G2[to].pb(nodo); vis[to]=1; q.push(to); } } } if(cant!=n){ continue; } //sum=0; //dfs(i,-1); res=min(res,sum); sum=0; } cout<<res<<"\n"; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'void dfs(int, int)':
bosses.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=0;i<G2[nodo].size();i++){
      |                 ~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for(int l=0;l<G[nodo].size();l++){
      |                         ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...