# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887181 | Caubethieunang | Bosses (BOI16_bosses) | C++14 | 799 ms | 50124 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 ll long long
#define LOG 19
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define FIRST_BIT(mask) __builtin_ctz((mask)&(-mask))
#define ERASE_BIT(mask) (mask)^((mask)&(-mask))
#define left _left
#define right _right
#define task "t"
using namespace std;
const ll INF=1e18;
const int iat=1e6+9;
const int mod=1e9+7;
void fast_IO()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
}
int n;
bool visited[iat];
vector <int> g[iat],store[iat];
ll sum,salary[iat];
void dfs(int u)
{
salary[u]=1;
for(int v : g[u])dfs(v),salary[u]+=salary[v];
sum+=salary[u];
}
void bfs(int s)
{
for(int i=1; i<=n; i++)
{
visited[i]=false;
g[i].clear();
}
queue <int> q;
q.push(s);
visited[s]=true;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v : store[u])
{
if(!visited[v])
{
visited[v]=true;
g[u].push_back(v);
q.push(v);
}
}
}
for(int i=1; i<=n; i++)
{
if(!visited[i])
{
sum=LLONG_MAX;
return;
}
}
dfs(s);
}
signed main()
{
fast_IO();
cin>>n;
for(int i=1; i<=n; i++)
{
int k;
cin>>k;
for(int j=1; j<=k; j++)
{
int x;
cin>>x;
store[x].push_back(i);
}
}
ll ans=LLONG_MAX;
for(int i=1; i<=n; i++)
{
sum=0;
bfs(i);
ans=min(ans,sum);
}
cout<<ans;
}
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... |