# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260286 | arnold518 | Bosses (BOI16_bosses) | C++14 | 710 ms | 888 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5000;
int N;
vector<int> adj[MAXN+10];
int dist[MAXN+10];
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++)
{
int p;
scanf("%d", &p);
while(p--)
{
int v;
scanf("%d", &v);
adj[v].push_back(i);
}
}
ll ans=1e18;
for(int i=1; i<=N; i++)
{
memset(dist, 0, sizeof(dist));
queue<int> Q;
Q.push(i); dist[i]=1;
while(!Q.empty())
{
int now=Q.front(); Q.pop();
for(auto nxt : adj[now])
{
if(dist[nxt]) continue;
dist[nxt]=dist[now]+1; Q.push(nxt);
}
}
ll t=0;
for(int i=1; i<=N; i++)
{
if(dist[i]==0) t=1e18;
t+=dist[i];
}
ans=min(ans, t);
}
printf("%lld\n", 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... |