Submission #791070

#TimeUsernameProblemLanguageResultExecution timeMemory
791070AndiRBosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; typedef long long ll; const int Nmax=5000; int n; bool vis[Nmax]; vector <pair<int, bool>> ad[Nmax]; queue <int> q; ll sol, mn=(ll)99999999999999999; int dfs(int nod){ int s=1; for (int i=0; i<ad[nod].size(); i++){ if (ad[nod][i].second==1){ ad[nod][i].second=0; s+=dfs(ad[nod][i].first); } } sol+=s; return s; } int main() { cin>>n; int m, a; for (int i=0; i<n; i++){ cin>>m; for (int j=0; j<m; j++){ cin>>a; a--; ad[a].push_back({i, 0}); } } for (int i=0; i<n; i++){ sol=0; vis[i]=1; q.push(i); while (!q.empty()){ for (int j=0; j<ad[q.front()].size(); j++){ if (vis[ad[q.front()][j].first]==0){ q.push(ad[q.front()][j].first); vis[ad[q.front()][j].first]=1; ad[q.front()][j].second=1; } } q.pop(); } for (int i=0; i<n; i++) vis[i]=0; dfs(i); if (sol<mn) mn=sol; } cout<<mn; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int dfs(int)':
bosses.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<ad[nod].size(); i++){
      |                   ~^~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:41:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for (int j=0; j<ad[q.front()].size(); j++){
      |                           ~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...