# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
418159 | T0p_ | Bosses (BOI16_bosses) | C++14 | 1 ms | 460 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;
int salary[5005];
vector<int> children[5005], g[5005];
bool visit[5005];
void init(int n)
{
for(int i=1 ; i<=n ; i++)
{
salary[i] = 0;
g[i].clear();
visit[i] = false;
}
}
void dfs(int u, int &sum)
{
int now = 1;
for(auto x : g[u])
{
dfs(x, sum);
now += salary[x];
}
salary[u] = now;
sum += now;
}
int main()
{
int n;
scanf(" %d",&n);
for(int i=1 ; i<=n ; i++)
{
int k;
scanf(" %d",&k);
while(k--)
{
int u;
scanf(" %d",&u);
children[u].push_back(i);
}
}
int ans = 1e9;
for(int i=1 ; i<=n ; i++)
{
init(n);
queue<int> bfs;
bfs.push(i);
visit[i] = true;
while(!bfs.empty())
{
int u = bfs.front();
bfs.pop();
for(auto x : children[u])
{
if(visit[x]) continue;
visit[x] = true;
g[u].push_back(x);
bfs.push(x);
}
}
int sum = 0;
dfs(i, sum);
ans = min(ans, sum);
}
printf("%d\n",ans);
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... |