# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755196 | vjudge1 | Bosses (BOI16_bosses) | C++17 | 1 ms | 340 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> ke[5005];
long long oo=1000000000000000;
long long kq;
long long danhdau[5005];
queue <int> q;
long long h[5005];
void bfs(int s)
{
while (q.size()) q.pop();
q.push(s);
long long tong=0;
while (q.size())
{
int s=q.front();
q.pop();
for (int i=0;i<ke[s].size();i++)
{
int v=ke[s][i];
if (danhdau[v]==0)
{
danhdau[v]=1;
h[v]=h[s]+1;
tong=tong+h[v];
q.push(v);
}
}
}
// cout << tong << " " << s << '\n';
kq=min(kq,tong+1);
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i=1;i<=n;i++)
{
int kk;
cin >> kk;
for (int i2=1;i2<=kk;i2++)
{
int kkk;
cin >> kkk;
ke[kkk].push_back(i);
}
}
kq=oo;
for (int dinh=1;dinh<=n;dinh++)
{
for (int i=1;i<=n;i++)
{
danhdau[i]=0;
h[i]=0;
}
h[dinh]=1;
danhdau[dinh]=1;
if (!ke[dinh].size()) continue;
bfs(dinh);
}
cout << kq;
}
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... |