Submission #735593

#TimeUsernameProblemLanguageResultExecution timeMemory
735593tigarBosses (BOI16_bosses)C++14
100 / 100
629 ms852 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int>graff[5050]; bool check[5050]; vector<pair<int, int> >ord; int reezz=0, ans=INT_MAX, brr=0; void bfs(int v, int br) { //cout<<v<<endl; if(check[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;} else if(check[v] and br==ord.size())return; check[v]=true; brr++; if(br==0)reezz+=1; else reezz+=ord[br-1].second; for(int i=0; i<graff[v].size(); i++) { if(!check[graff[v][i]] and br!=0){ord.push_back({graff[v][i], ord[br-1].second+1}); /*tree[v].push_back(graff[v][i]);*/} else if (!check[graff[v][i]] and br==0)ord.push_back({graff[v][i], 2}); } if(br==ord.size())return; bfs(ord[br].first, br+1); } int main() { ios_base::sync_with_stdio(false); //cin.tie(0); cout.tie(0); cin>>n; for(int i=1; i<=n; i++) { int k; cin>>k; for(int j=0; j<k; j++) { int a; cin>>a; graff[a].push_back(i); } } for(int i=1; i<=n; i++) { reezz=0; brr=0; for(int i=1; i<=n; i++)check[i]=false; ord.clear(); bfs(i, 0); if(brr==n)ans=min(ans, reezz); } cout<<ans; return 0; } /*4 1 2 1 1 1 1 1 1 9*/

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int, int)':
bosses.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     if(check[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;}
      |                     ~~^~~~~~~~~~~~
bosses.cpp:15:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     else if(check[v] and br==ord.size())return;
      |                          ~~^~~~~~~~~~~~
bosses.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0; i<graff[v].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
bosses.cpp:25:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if(br==ord.size())return;
      |        ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...