# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857340 | teesla | Bosses (BOI16_bosses) | C++14 | 1 ms | 436 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;
vector<vector<int>> adj;
vector<int> vis;
int res = 0;
void bfs(int x){
queue<pair<int,int>> q;
q.push({x,1});
vis[x] = 1;
while(!q.empty()){
auto [a,b] = q.front();q.pop();
if(vis[a]< b) continue;
res += b;
for(auto i: adj[a]){
if(vis[i] != -1) continue;
vis[i] = b + 1;
q.push({i, vis[i]});
}
}
}
int main(){
int n; cin >> n;
adj.resize(n);
for(int i=0; i<n; i++){
int k; cin >> k;
for(int j =0; j<k; j++){
int a; cin >> a; a--;
adj[a].push_back(i);
}
}
int menor = 0;
for(int i=0; i<n; i++){
vis.assign(n,-1);
res = 0;
bfs(i);
if(i ==0) menor =res;
else menor = min(menor, res);
}
cout << menor << 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... |