Submission #292303

#TimeUsernameProblemLanguageResultExecution timeMemory
292303Ahmad_HasanBosses (BOI16_bosses)C++17
100 / 100
1219 ms99064 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int> >adj; vector<vector<int> >adj2; int vis[5005]; int vis2[5005]; int n; pair<int,int> dfs(int cr){ vis[cr]=1; pair<int,int>tmp; tmp.first=0,tmp.second=0; int cntc=0,cnttl=0; for(int i=0;i<adj2[cr].size();i++){ if(!vis[adj2[cr][i]]){ tmp=dfs(adj2[cr][i]); cntc+=tmp.first; cnttl+=tmp.second; } } vis[cr]=0; return {cntc+1,cnttl+cntc+1}; } int bfs(int cr){ queue<int>q; q.push(cr); vis2[cr]=1; int cnt=0; int dpt=1; int ttl=1; while(!q.empty()){ int ncr=q.front(); q.pop(); ttl--; cnt+=dpt; for(int i=0;i<adj[ncr].size();i++){ if(!vis2[adj[ncr][i]]){ vis2[adj[ncr][i]]=1; adj2[ncr].push_back(adj[ncr][i]); q.push(adj[ncr][i]); } } if(ttl==0){ ttl=q.size(); dpt++; } } return cnt; } int main() {///{} ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; adj=vector<vector<int> >(n+1); vector<vector<int> >mtx(n+1,vector<int>(n+1)); for(int i=1;i<=n;i++){ int nt; cin>>nt; while(nt--){ int tm; cin>>tm; if(!mtx[tm][i]) adj[tm].push_back(i); mtx[tm][i]=1; } } int ans=INT_MAX; memset(vis,0,sizeof(vis)); adj2.resize(n+1); for(int i=1;i<=n;i++){ memset(vis2,0,sizeof(vis2)); for(int j=1;j<=n;j++){ adj2[j].clear(); } int cr=bfs(i); int f=1; for(int i=1;i<=n;i++) if(!vis2[i]){ f=0; break; } if(f) ans=min(ans,cr); } cout<<ans<<'\n'; return 0; } /*** 4 1 2 1 1 1 2 1 2 */

Compilation message (stderr)

bosses.cpp: In function 'std::pair<int, int> dfs(int)':
bosses.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<adj2[cr].size();i++){
      |                 ~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int bfs(int)':
bosses.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int i=0;i<adj[ncr].size();i++){
      |                     ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...