Submission #764337

#TimeUsernameProblemLanguageResultExecution timeMemory
764337EllinorBosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i = (a); i < (b); i++)
typedef long long ll;

int N,k;
vector<vector<int>> graph;
vector<bool> visited;
ll a;

queue<pair<int,int>> q; //node, level


void bfs_calc(int node, int level) //bfs !
{
    a+=level;
    rep(i,0,graph[node].size()){
        if (!visited[graph[node][i]]) {
            q.push({graph[node][i],level+1});
            visited[graph[node][i]]=true;
        }
    }
}


int32_t main()
{
    cin>>N;
    graph.assign(N,{});
    int root=-1;
    rep(i,0,N){
        cin>>k;
        rep(j,0,k){
            cin>>a;
            a--;
            //boss to employee
            graph[a].push_back(i);
        }
        if(k==0)root=i;
    }

    ll ans=1e17; //hm !
    //ki = 0 ?? !
    if(root==-1){
        rep(i,0,N){
            visited.assign(N,false);
            //check all visited
            a=0;
            q.push({i,1});
            visited[i]=true;
            while(!q.empty()){
                auto x=q.front();
                q.pop();
                bfs_calc(x.first,x.second);
            }
            while(true){
                rep(i,0,visited.size()){
                    if(!visited[i]){
                        assert(1==0);
                    }
                }
                break;
            }
            ans=min(ans,a);
        }
    }
    else{
        visited.assign(N,false);
        a=0;
        q.push({root,1});
        visited[root]=true;
        while(!q.empty()){
            auto x=q.front();
            q.pop();
            bfs_calc(x.first,x.second);
        }
        while(true){
            rep(i,0,visited.size()){
                if(!visited[i]){
                    assert(1==0);
                }
            }
            break;
        }
        ans=a;
    }

    cout << ans;
}

Compilation message (stderr)

bosses.cpp: In function 'void bfs_calc(int, int)':
bosses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i < (b); i++)
      |                                       ^
bosses.cpp:18:5: note: in expansion of macro 'rep'
   18 |     rep(i,0,graph[node].size()){
      |     ^~~
bosses.cpp: In function 'int32_t main()':
bosses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i < (b); i++)
      |                                       ^
bosses.cpp:58:17: note: in expansion of macro 'rep'
   58 |                 rep(i,0,visited.size()){
      |                 ^~~
bosses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i < (b); i++)
      |                                       ^
bosses.cpp:79:13: note: in expansion of macro 'rep'
   79 |             rep(i,0,visited.size()){
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...