# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
290669 | Dymo | Bosses (BOI16_bosses) | C++14 | 845 ms | 5480 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 pb push_back
#define all(n) n.begin(),n.end()
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second
using namespace std;
const ll maxn=2e5+500;
const ll mod=1e9+7 ;
const ll base=500;
/// con 17 ngay
vector<ll> adj[maxn];
bool dd[maxn];
ll ans=1e15;
ll ans1=0;
ll sum[maxn];
void bfs(ll u)
{
queue<pll> q;
q.push(make_pair(1,u));
while (!q.empty())
{
auto p= q.front() ;
q.pop();
ll u=p.ss;
dd[u]=1;
ans1=ans1+p.ff;
for (auto to:adj[u])
{
if (dd[to]) continue;
dd[to]=1;
q.push(make_pair(p.ff+1,to));
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("test.txt","r",stdin);
if (fopen("Farm.INP","r"))
{
freopen("Farm.INP","r",stdin);
freopen("Farm.OUT","w",stdout);
}
ll n;
cin>>n ;
for (int i=1; i<=n; i++)
{
ll x;
cin>>x;
while (x--)
{
ll t;
cin>> t;
adj[t].pb(i);
}
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
dd[j]=0;
ans1=0;
bfs(i);
bool x=false;
for (int j=1; j<=n; j++)
{
if (!dd[j])
{
x=true;
break;
}
}
if (!x)
{
ans=min(ans,ans1);
}
}
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... |