Submission #66420

#TimeUsernameProblemLanguageResultExecution timeMemory
66420Adhyyan1252Bosses (BOI16_bosses)C++11
100 / 100
874 ms952 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<vector<int> > g(n); for(int i = 0; i < n; i++){ int k; cin>>k; for(int j = 0; j < k; j++){ int temp; cin>>temp; g[temp-1].push_back(i); } } long long best = LONG_LONG_MAX; for(int root = 0; root < n; root++){ queue<pair<int, int> > q; vector<bool> done(n, false); done[root] = true; q.push({root, 1}); long long ans = 0; int count = 0; while(!q.empty()){ count++; auto top = q.front(); q.pop(); ans += top.second; for(int i = 0; i < g[top.first].size(); i++){ if(done[g[top.first][i]]) continue; q.push({g[top.first][i], top.second+1}); done[g[top.first][i]] = true; } } //cout<<"R: "<<root<<" "<<count<<" "<<ans<<endl; if(count == n) best = min(best, ans); } cout<<best<<endl; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:27:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < g[top.first].size(); i++){
                   ~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...