Submission #422143

#TimeUsernameProblemLanguageResultExecution timeMemory
422143victoriadBosses (BOI16_bosses)C++14
100 / 100
734 ms708 KiB
#include <cmath> #include <cstdio> #include <iostream> #include <utility> #include <algorithm> #include <vector> #include <set> #include <queue> #include <map> using namespace std; int x,t; void bfs(vector<vector<int> >&g,int n,int y){ queue<int>q; q.push(n); vector<int>s(y,1e9); s[n]=1; while(!q.empty()){ t++; int a=q.front(); q.pop(); for(int i:g[a]){ if(s[i]>s[a]+1){ s[i]=s[a]+1; x+=s[i]; q.push(i); } } } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n,k,a; cin>>n; vector<vector<int> >em(n); int r=-1; for(int i=0;i<n;i++){ cin>>k; while(k--){ cin>>a; a--; em[a].push_back(i); } } int ans=1e9; for(int i=0;i<n;i++){ x=1; t=0; bfs(em,i,n); if(t==n){ ans=min(x,ans); } } cout<<ans<<"\n"; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:38:6: warning: unused variable 'r' [-Wunused-variable]
   38 |  int r=-1;
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...