Submission #39796

# Submission time Handle Problem Language Result Execution time Memory
39796 2018-01-18T17:54:50 Z Pajaraja Bosses (BOI16_bosses) C++14
0 / 100
0 ms 2164 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> g[5007];
bool vi[5007];
int dist[5007],n;
long long bfs(int s)
{
	queue<int> bfsq;
	bfsq.push(s);
	fill(vi,vi+5007,false);
	fill(dist,dist+5007,-1);
	vi[s]=true;
	dist[s]=0;
	while(!bfsq.empty())
	{
		int u=bfsq.front();
		for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]])
		{
			vi[g[u][i]]=true;
			dist[g[u][i]]=dist[u]+1;
			bfsq.push(g[u][i]);
		}
		bfsq.pop();
	}
	long long sum=n;
	for(int i=1;i<=n;i++) sum+=dist[i];
	return sum;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int t,z;
		scanf("%d",&t);
		for(int j=0;j<t;j++)
		{
			scanf("%d",&z);
			g[z].push_back(i);
		}
	}
	long long sol=1000000000000000000LL;
	for(int i=1;i<=n;i++) sol=fmin(sol,bfs(i));
	printf("%d",sol);
}

Compilation message

bosses.cpp: In function 'long long int bfs(int)':
bosses.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]])
                ^
bosses.cpp: In function 'int main()':
bosses.cpp:44:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d",sol);
                 ^
bosses.cpp:31:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bosses.cpp:35:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
                 ^
bosses.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&z);
                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2164 KB Output is correct
2 Correct 0 ms 2164 KB Output is correct
3 Incorrect 0 ms 2164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2164 KB Output is correct
2 Correct 0 ms 2164 KB Output is correct
3 Incorrect 0 ms 2164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2164 KB Output is correct
2 Correct 0 ms 2164 KB Output is correct
3 Incorrect 0 ms 2164 KB Output isn't correct
4 Halted 0 ms 0 KB -