Submission #208527

#TimeUsernameProblemLanguageResultExecution timeMemory
208527jzhBosses (BOI16_bosses)C++14
67 / 100
1588 ms888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll>v[5010]; ll level[5010]; bool vis[5010]; ll sum; ll dfs(ll node){ //if (vis[node])return 0; vis[node]=1; ll ret=0; for (ll i=0;i<v[node].size();i++){ if (level[v[node][i]]==level[node]+1&&!vis[v[node][i]]){ ret+=dfs(v[node][i]); } } ret++; sum+=ret; //cout<<node<<' '<<ret<<'\n'; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n,i,x,y,k,ans=INT_MAX,i1,w,maxlevel; cin>>n; for (i=1;i<=n;i++){ cin>>k; while (k--){ cin>>x; v[x].push_back(i); } } for (i=1;i<=n;i++){ queue<pair<ll,ll> >q; q.push({1,i}); for (i1=1;i1<=n;i1++)level[i1]=-1,vis[i1]=0; level[i]=1; sum=0; maxlevel=1; while (!q.empty()){ x=q.front().second; w=q.front().first; q.pop(); maxlevel=max(maxlevel,w); for (i1=0;i1<v[x].size();i1++){ if (level[v[x][i1]]==-1){ level[v[x][i1]]=w+1; q.push({w+1,v[x][i1]}); //cout<<x<<'.'<<v[x][i1]<<'\n'; } } } for (i1=1;i1<=n;i1++){ if (level[i1]==-1){ //cout<<i1<<"..."<<'\n'; break; } } if (i1!=n+1){ continue; } dfs(i); ans=min(ans,sum); //cout<<i<<'\n'; //cout<<sum<<'\n'; } cout<<ans<<'\n'; }

Compilation message (stderr)

bosses.cpp: In function 'll dfs(ll)':
bosses.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll i=0;i<v[node].size();i++){
                 ~^~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:47:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i1=0;i1<v[x].size();i1++){
                       ~~^~~~~~~~~~~~
bosses.cpp:25:14: warning: unused variable 'y' [-Wunused-variable]
     ll n,i,x,y,k,ans=INT_MAX,i1,w,maxlevel;
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...