# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082649 | BlueGlaucus1 | Bosses (BOI16_bosses) | C++17 | 426 ms | 856 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 <iostream>
#include <vector>
#include <queue>
using namespace std;
bool visited[5005];
int levels[5005];
vector<int> vw[5005];
int main(){
int n; cin >> n;
for(int i =1; i <=n;i++){
int a; cin >> a;
for(int l =0; l <a;l++){
int k; cin >> k;
vw[k].push_back(i);
}
}
int answer=1000000000;
for(int i = 1; i <=n;i++){
int count = 0;
queue<int> a;
int temp = 0;
fill(visited, visited+n+3, 0);
fill(levels, levels+n+3, 0);
a.push(i);
levels[i] = 1;
visited[i] = true;
while(!a.empty()){
count++;
int f = a.front();
a.pop();
temp +=levels[f];
for(int k = 0; k <vw[f].size();k++){
int va= vw[f][k];
if(!visited[va]){
levels[va] = levels[f] + 1;
visited[va] = 1;
a.push(va);
}
}
}
if(count==n){
answer = min(answer, temp);
}
}
cout << answer;
}
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... |