제출 #156294

#제출 시각아이디문제언어결과실행 시간메모리
156294LawlietBosses (BOI16_bosses)C++14
0 / 100
2 ms504 KiB
#include <bits/stdc++.h>

#define MAX 5010

using namespace std;

int n;
int n1, n2;

int ans[MAX];
int dist[MAX];

bool marc[MAX];

vector<int> grafo[MAX];

queue<int> q;

void add(int cur, int root, int d)
{
	q.push( cur );
	dist[ cur ] = d;
	marc[ cur ] = true;

	ans[ root ] += dist[ cur ];
}

void BFS(int s)
{
	memset(marc , 0 , sizeof( marc ));

	add( s , s , 1 );

	while( !q.empty() )
	{
		int cur = q.front();
		q.pop();

		for(int i = 0 ; i < grafo[ cur ].size() ; i++)
		{
			int prox = grafo[ cur ][ i ];

			if( !marc[prox] )
				add( prox , s , dist[ cur ] + 1 );
		}
	}
}

int main()
{
	scanf("%d",&n);

	for(int i = 1 ; i <= n ; i++)
	{
		scanf("%d",&n1);

		for(int j = 1 ; j <= n1 ; j++)
		{
			scanf("%d",&n2);

			grafo[ n2 ].push_back( i );
		}
	}

	for(int i = 1 ; i <= n ; i++)
		BFS( i );

	int mn = ans[ 1 ];

	for(int i = 2 ; i <= n ; i++)
		mn = min(mn , ans[ i ]);

	printf("%d\n",mn);
}

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'void BFS(int)':
bosses.cpp:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < grafo[ cur ].size() ; i++)
                   ~~^~~~~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bosses.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n1);
   ~~~~~^~~~~~~~~~
bosses.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&n2);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...