# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66420 | Adhyyan1252 | Bosses (BOI16_bosses) | C++11 | 874 ms | 952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |