# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
220153 | MKopchev | Bosses (BOI16_bosses) | C++14 | 803 ms | 760 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;
const int nmax=5e3+42,inf=1e4+42;
int n;
vector<int> adj[nmax];
int dist[nmax];
queue< pair<int/*node*/,int/*dist*/> > q;
int bfs(int start)
{
for(int i=1;i<=n;i++)dist[i]=inf;
q.push({start,1});
while(q.size())
{
pair<int/*node*/,int/*dist*/> cur=q.front();
q.pop();
if(dist[cur.first]!=inf)continue;
dist[cur.first]=cur.second;
for(auto k:adj[cur.first])
q.push({k,cur.second+1});
}
int ret=0;
for(int i=1;i<=n;i++)ret=ret+dist[i];
//cout<<start<<" -> ";for(int i=1;i<=n;i++)cout<<dist[i]<<" ";cout<<endl;
return ret;
}
int main()
{
scanf("%i",&n);
for(int i=1;i<=n;i++)
{
int sz,u;
scanf("%i",&sz);
for(int j=1;j<=sz;j++)
{
scanf("%i",&u);
adj[u].push_back(i);
}
}
int output=n*n;
for(int i=1;i<=n;i++)
output=min(output,bfs(i));
printf("%i\n",output);
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... |