Submission #107346

# Submission time Handle Problem Language Result Execution time Memory
107346 2019-04-23T12:07:28 Z MohamedAhmed0 Bosses (BOI16_bosses) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 5005 ;
int vis[MAX] , par[MAX][MAX] , can[MAX] ;
long long dp[MAX] , cost = 0;

vector< vector<int> >adj(MAX) ;

int n , cnt = 0 ;

void bfs(int src)
{
    queue<int>q ;
    q.push(src) ;
    vis[src] = src ;
    par[src][src] = 0 ;
    while(!q.empty())
    {
        int node = q.front() ;
        q.pop() ;
        cnt++ ;
        for(auto &child : adj[node])
        {
            if(vis[child] == src)
                continue ;
            vis[child] = src ;
            par[src][child] = node ;
            q.push(child) ;
        }
    }
    return ;
}

int src ;

void dfs(int node)
{
    for(auto &child : adj[node])
    {
        if(par[src][child] == node)
        {
            dfs(child) ;
            dp[node] += dp[child] ;
        }
    }
    dp[node]++;
    cost += dp[node] * 1ll;
    return ;
}

/*int readint()
{
    char c ;
    c = getchar() ;
    while(true)
    {
        if(c >= '0' && c <= '9')
            break ;
        c = getchar() ;
    }
    int result = (c - '0') ;
    c = getchar() ;
    while(true)
    {
        if(c < '0' || c > '9')
            break ;
        result = result * 10 + (c - '0') ;
        c = getchar() ;
    }
    return result ;
}*/

int main()
{
    scanf("%d" , &n) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        int m ;
        scanf("%d" , &x) ;
        while(m--)
        {
            int x ;
            scanf("%d" , &x) ;
            adj[x].push_back(i) ;
        }
    }
    long long ans = 1e18 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        cnt = 0 ;
        bfs(i) ;
        if(cnt == n)
            can[i] = 1 ;
    }
    for(int i = 1 ; i <= n ; ++i)
    {
        if(can[i] == 0)
            continue ;
        memset(dp , 0 , sizeof(dp)) ;
        src = i ;
        cnt = 0 , cost = 0;
        dfs(i) ;
        ans = min(ans , cost) ;
    }
    return printf("%lld" , ans) , 0 ;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:81:23: error: 'x' was not declared in this scope
         scanf("%d" , &x) ;
                       ^
bosses.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d" , &n) ;
     ~~~~~^~~~~~~~~~~
bosses.cpp:85:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d" , &x) ;
             ~~~~~^~~~~~~~~~~