# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292230 | Abdelrahman | Bosses (BOI16_bosses) | C++17 | 615 ms | 768 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>
#define endl '\n'
#define modulo 1000000007
//#define int long long
#pragma GCC optimize("-Ofast")
#define float double
#define PI 3.141592653589793238462643383279502884
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
vector<int> children[5001];
bool visited[5001] = {0};
int mini=INT_MAX;
int finale = 0, done=0;
void solve(int emp)
{
vector<pair<int, int> > v;
visited[emp]=1;
v.push_back({emp, 1});
done++;
finale++;
int x=0;
while (x!=v.size())
{
if (finale>mini)
break;
auto p = v[x];
for (int i=0;i<children[p.first].size();i++)
{
int a = children[p.first][i];
//cout<<a<<" ";
if (visited[a])
continue;
done++;
visited[a]=1;
v.push_back({a, p.second+1});
finale+=p.second+1;
}
x++;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for (int i=0;i<n;i++)
{
int a;
cin>>a;
while (a--)
{
int b;
cin>>b;
children[b-1].push_back(i);
}
}
for (int i=0;i<n;i++)
{
solve(i);
if (done==n)
{
mini = min(finale, mini);
}
memset(visited, 0, sizeof(visited));
finale = 0;
done=0;
}
cout<<mini;
}
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... |