Submission #1307359

#TimeUsernameProblemLanguageResultExecution timeMemory
1307359tarner_exeBosses (BOI16_bosses)C++20
100 / 100
500 ms197664 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define elif else if
#define ft first
#define sc second
#define pb push_back
#define pII pair<int,int>
#define fast_IO ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)

const int sizen = 2e6+11;
const int sizen_s = 5e3+32;
const int oo = 1e16+11;

int bfs_odl[sizen_s][sizen_s];
int WYNIKI[sizen_s];
int N,K;
int t=1, X;
vector<int>vec[sizen];



void bfs(int kolor)
{
    queue<int>Q;
    Q.push(kolor);
    int e =0;
    while(!Q.empty())
    {
        e++;
        int v = Q.front();
        for(auto i : vec[v])
        {
            if(bfs_odl[kolor][i] == 0)
            {
                bfs_odl[kolor][i] = bfs_odl[kolor][v] + 1;
                WYNIKI[kolor] += bfs_odl[kolor][i];
                Q.push(i);
            }
        }
        Q.pop();
    }
    if(e != N)
    {
        WYNIKI[kolor] = oo;
    }
}

void solve()
{
    cin >> N;
    for(int i = 1; i<= N ; i++)
    {
        cin >> K;
        for (int j = 1 ; j <= K ; j++)
        {
            cin >> X;
            vec[X].pb(i);
        }
    }
    int W = oo;
    for (int i = 1 ; i<= N ; i++)
    {
        bfs_odl[i][i] = 1;
        bfs(i);
        W = min(W,WYNIKI[i]);
    }
    cout << W+1 << "\n";
}
signed main()
{
    //cin >> t;
    while(t--)
    {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...