Submission #27021

#TimeUsernameProblemLanguageResultExecution timeMemory
27021bill_kondoBosses (BOI16_bosses)C++14
100 / 100
703 ms2316 KiB
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define debug(args...) fprintf(stderr,args)
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define REP(i,a,b) for(int i = a; i >= b; --i)

typedef long long ll;
typedef pair<int,int>pii;

const int maxn = 5e3 + 10;
const ll INF = 1e18;

int n;
vector<int>g[maxn];

bool mrk[maxn];
ll dis[maxn];

ll solve(int root){
	FOR(i,1,n){
		mrk[i] = false;
		dis[i] = INF;
	}
	queue<int>Q;
	dis[root] = 1;
	mrk[root] = true;
	Q.push(root);
	while(!Q.empty()){
		int v = Q.front();
		Q.pop();
		for(auto u: g[v])
			if(!mrk[u]){
				mrk[u] = true;
				dis[u] = dis[v] + 1;
				Q.push(u);
			}
	}
	ll ret = 0;
	FOR(i,1,n){
		if(!mrk[i]) return INF;
		ret += dis[i];
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	FOR(i,1,n){
		int k;
		scanf("%d",&k);
		while(k--){
			int node;
			scanf("%d",&node);
			g[node].pb(i);
		}
	}
	ll ans = INF;
	FOR(i,1,n) ans = min(ans,solve(i));
	printf("%lld\n",ans);
	return 0;
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:49:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bosses.cpp:52:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k);
                 ^
bosses.cpp:55:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&node);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...