Submission #158983

#TimeUsernameProblemLanguageResultExecution timeMemory
158983InfiniteJestBosses (BOI16_bosses)C++14
0 / 100
2 ms760 KiB
#include <iostream> #include <fstream> #include <vector> #include <queue> #include <algorithm> #include <math.h> #include <map> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); typedef long long ll; int n; vector<int> nodi[5001]; vector<int> p[5001]; bool vis[5001]; int minn=1e9; int val[5001]; void bfs(int k){ queue<int> q; q.push(k); vis[k]=1; while(!q.empty()){ int cur=q.front(); q.pop(); for(int i=0;i<nodi[cur].size();i++){ if(vis[nodi[cur][i]])continue; vis[nodi[cur][i]]=1; p[cur].pb(nodi[cur][i]); q.push(nodi[cur][i]); } } } int dfs(int k){ int sum=0; for(int i=0;i<p[k].size();i++)sum+=dfs(p[k][i]); val[k]=sum+1; return val[k]; } int main(){ cin>>n; for(int i=0;i<n;i++){ int k; cin>>k; for(int y=0;y<k;y++){ int a; cin>>a; nodi[a-1].pb(i); } } for(int i=0;i<n;i++){ for(int y=0;y<n;y++){ p[y].clear(); vis[y]=0; val[y]=0; } bfs(i); dfs(i); int sum=0; for(int y=0;y<n;y++)sum+=val[y]; minn=min(minn,sum); //cout<<"i "<<i<<" v "<<sum<<endl; } cout<<minn; }

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<nodi[cur].size();i++){
                 ~^~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int dfs(int)':
bosses.cpp:44:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<p[k].size();i++)sum+=dfs(p[k][i]);
               ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...