# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103613 | Nnandi | Bosses (BOI16_bosses) | C++14 | 628 ms | 888 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;
typedef long long ll;
const int maxn = 5005;
vector<int> graf[maxn];
int tav[maxn];
int n;
void ujra() {
for(int i=0;i<n;i++) {
tav[i] = -1;
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=0;i<n;i++) {
int k;
cin>>k;
for(int j=0;j<k;j++) {
int from;
cin>>from;
from--;
graf[from].push_back(i);
}
}
ll summa = (ll)n*(n+1);
for(int i=0;i<n;i++) {
ujra();
vector<int> sor(1,i);
tav[i] = 0;
int it = 0;
ll jel = (ll) n;
while(it < sor.size()) {
int akt = sor[it];
jel += tav[akt];
for(int s:graf[akt]) {
if(tav[s] == -1) {
tav[s] = tav[akt] + 1;
sor.push_back(s);
}
}
it++;
}
if(sor.size() == n && summa > jel) {
summa = jel;
}
}
cout<<summa<<endl;
return 0;
}
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... |