Submission #985403

#TimeUsernameProblemLanguageResultExecution timeMemory
985403Octa_pe_infoBosses (BOI16_bosses)C++14
0 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; vector<vector<int>>tabel; vector<bool>viz; vector<int>pasi; int cnt=0,stot=0; void bfs(int nod){ queue<int>q; viz[nod]=1; q.push(nod); pasi[nod]=1; stot=1; while(!q.empty()){ int curent=q.front(); q.pop(); for(auto i : tabel[curent]) if(!viz[i]){ viz[i]=1;/// pasi[i]=pasi[curent]+1; stot+=pasi[i]; q.push(i);/// cnt++;/// } } } /* int dfs(int nod){ int sal=1; for(auto i : tabel[nod]) if(pasi[i]-1==pasi[nod]) sal+=dfs(i); stot+=sal; return sal; } */ int main() { int n; cin>>n; tabel.resize(n+1); for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=1;j<=k;j++){ int x; cin>>x; tabel[x].push_back(i); } } int salmin=(1<<30); for(int i=1;i<=n;i++){ viz.resize(n+1,0); pasi.resize(n+1,0); cnt=0; stot=0; bfs(i); if(cnt==n-1){ salmin=min(salmin,stot); } } cout<<salmin; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...