Submission #1017073

# Submission time Handle Problem Language Result Execution time Memory
1017073 2024-07-08T20:17:01 Z ivaziva Bosses (BOI16_bosses) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 5010

long long n;
vector<long long> adj[MAXN];
long long dist[MAXN];
queue<long long> bfsq;

void bfs(long long pret)
{
    for (long long i=1;i<=n;i++) dist[i]=LLONG_MAX;
    dist[pret]=1;bfsq.push(pret);
    while (bfsq.empty()==false)
    {
        long long node=bfsq.front();
        bfsq.pop();
        for (long long sled:adj[node])
        {
            if (dist[sled]!=LLONG_MAX) continue;
            dist[sled]=dist[node]+1;
            bfsq.push(sled);
        }
    }
}

int main()
{
    cin>>n;
    for (long long i=1;i<=n;i++)
    {
        long long s;cin>>s;
        for (long long j=0;j<s;j++)
        {
            long long x;cin>>x;
            adj[x].push_back(i);
        }
    }
    long long ans=LLONG_MAX;
    for (long long i=1;i<=n;i++)
    {
        bfs(i);long long sol=0;
        for (long long j=1;j<=n;j++) sol+=dist[j];
        ans=min(ans,sol);
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -