답안 #1014571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014571 2024-07-05T07:36:51 Z qnicondavid23 Bosses (BOI16_bosses) C++14
0 / 100
1 ms 436 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
int n;
int x,a;
vector<vector<int>> A;
vector<bool> fr;
vector<vector<int>> G;
void bfs(int nod)
{
	queue<int> Q;
	Q.push(nod);
	fr[nod]=1;
	while(!Q.empty())
	{
       int cap=Q.front();
	   Q.pop();
	   for(int i=0;i<A[cap].size();i++)
	   {
		   int vecin=A[cap][i];
		   if(!fr[vecin])
		   {
			   G[cap].push_back(vecin);
			   fr[vecin]=1;
			   Q.push(vecin);
		   }
	   }
	} 
}
int sum=0;
int dfs(int nod)
{
	int s=0;
    for(int i=0;i<G[nod].size();i++)
	{
		int vecin=G[nod][i];
		s=s+dfs(vecin);
	}
	sum=sum+s+1;
	return s+1;
}
int main() {
	cin>>n;
	A.resize(n+1);
	for(int i=1;i<=n;i++)
	{
         cin>>x;
		 for(int j=0;j<x;j++)
		 {
			 cin>>a;
			 A[a].push_back(i);
		 }
	}
	int mini=0x3f3f3f3f;
	for(int i=1;i<=n;i++)
	{
         fr.resize(0);
		 fr.resize(n+1);
		 G.resize(0);
		 G.resize(n+1);
		 sum=0;
		 bfs(i);
		 dfs(i);
		 mini=min(mini,sum);
	}
	cout<<mini;
return 0;
}	

Compilation message

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<A[cap].size();i++)
      |                 ~^~~~~~~~~~~~~~
bosses.cpp: In function 'int dfs(int)':
bosses.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<G[nod].size();i++)
      |                 ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -