# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
368055 | leinad2 | Bosses (BOI16_bosses) | C++17 | 843 ms | 748 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<int>adj[5010];
int n, i, j, k, a, b, ans=1e9;
int main()
{
ios_base::sync_with_stdio(!cin.tie(NULL));
for(cin>>n;i++<n;)
{
cin>>a;
while(a--)
{
cin>>b;
adj[b].push_back(i);
}
}
for(i=0;i++<n;)
{
int dist[5010]={};
dist[i]=1;
queue<int>q;
q.push(i);
while(q.size())
{
a=q.front();
q.pop();
for(j=0;j<adj[a].size();j++)
{
if(!dist[adj[a][j]])
{
dist[adj[a][j]]=dist[a]+1;
q.push(adj[a][j]);
}
}
}
int ret=0;
for(j=0;j++<n;)
{
if(dist[j]==0)goto w;
ret+=dist[j];
}
ans=min(ans, ret);
w:;
}
cout<<ans;
}
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... |