# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
405174 | T0p_ | Bosses (BOI16_bosses) | C++14 | 1 ms | 588 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 ans;
int deg_in[5050], deg_out[5050], sub[5050];
bool mark[5050], pushed[5050];
vector<int> g[5050], gt[5050], edge[5050];
void dfs(int u)
{
sub[u] = 1;
for(auto x : edge[u])
{
dfs(x);
sub[u] += sub[x];
}
ans += sub[u];
}
int main()
{
int n;
scanf(" %d",&n);
for(int i=1 ; i<=n ; i++)
{
scanf(" %d",°_in[i]);
for(int j=1 ; j<=deg_in[i] ; j++)
{
int d;
scanf(" %d",&d);
g[d].push_back(i);
gt[i].push_back(d);
deg_out[d]++;
}
}
int root;
for(int i=1 ; i<=n ; i++)
{
int u = 0;
for(int j=1 ; j<=n ; j++)
{
if(mark[j]) continue;
if(deg_out[j] > deg_out[u]) u = j;
}
mark[u] = true;
if(i == 1) root = u;
for(auto x : g[u])
{
if(mark[x] || pushed[x]) continue;
pushed[x] = true;
edge[u].push_back(x);
}
for(auto x : gt[u])
{
deg_out[x]--;
}
}
dfs(root);
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... |