Submission #208757

#TimeUsernameProblemLanguageResultExecution timeMemory
208757arnold518Bosses (BOI16_bosses)C++14
100 / 100
724 ms760 KiB
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 5000;

int N;
int dist[MAXN+10];
vector<int> adj[MAXN+10];

int main()
{
	int i, j;

	scanf("%d", &N);
	for(i=1; i<=N; i++)
	{
		int t; scanf("%d", &t);
		while(t--)
		{
			int v;
			scanf("%d", &v);
			adj[v].push_back(i);
		}
	}

	int ans=987654321;
	for(i=1; i<=N; i++)
	{
		queue<int> Q; int x=0;
		memset(dist, -1, sizeof(dist));
		dist[i]=1; Q.push(i);
		int cnt=0;
		while(!Q.empty())
		{
			int now=Q.front(); Q.pop();
			x+=dist[now]; cnt++;
			for(auto nxt : adj[now]) if(dist[nxt]==-1) dist[nxt]=dist[now]+1, Q.push(nxt);
		}
		if(cnt==N) ans=min(ans, x);
	}
	printf("%d\n", ans);
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:16:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
bosses.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bosses.cpp:21:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t; scanf("%d", &t);
          ~~~~~^~~~~~~~~~
bosses.cpp:25:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &v);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...