Creative Code

[1043번]거짓말 본문

백준 문제풀이

[1043번]거짓말

빛하루 2023. 9. 24. 17:33

https://www.acmicpc.net/problem/1043

 

1043번: 거짓말

지민이는 파티에 가서 이야기 하는 것을 좋아한다. 파티에 갈 때마다, 지민이는 지민이가 가장 좋아하는 이야기를 한다. 지민이는 그 이야기를 말할 때, 있는 그대로 진실로 말하거나 엄청나게

www.acmicpc.net

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int graph[51][51];

int main() {
	cout.tie(0);
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;				//N : 사람의 수 , M : 파티의 수
	cin >> N >> M;
	int num;
	cin >> num;				//num : 진실을 아는 사람의 수
	map<int, bool>truth;		//진실을 아는 사람을 저장할 map

	for (int i = 1; i <= N; i++) {
		truth[i] = false;		// 초기값 저장
	}

	for (int i = 0; i < num; i++) {
		int k;
		cin >> k;
		truth[k] = true;		// 진실을 아는 사람 저장
	}

	vector<vector<int>>human;   // 전체 파티 정보를 저장할 벡터
	while (M--) {
		vector<int>party;
		int k;
		cin >> k;
		for (int i = 0; i < k; i++) {
			int a;
			cin >> a;
			party.push_back(a);
		}
		human.push_back(party);
	}
	for (int k = 0; k < 50; k++) {
		for (int i = 0; i < human.size(); i++) {
			bool check = false;
			for (int j = 0; j < human[i].size(); j++) {
				if (truth[human[i][j]] == true) {
					check = true;
				}
			}
			if (check == true) {
				for (int j = 0; j < human[i].size(); j++) {
					truth[human[i][j]] = true;
				}
			}
		}
	}
	int answer = 0;
	for (int i = 0; i < human.size(); i++) {
		bool check = false;
		for (int j = 0; j < human[i].size(); j++) {
			if (truth[human[i][j]] == true) {
				check = true;
			}
		}
		if (check == false) {
			answer++;
		}
	}
	cout << answer << '\n';
}

'백준 문제풀이' 카테고리의 다른 글

[1806번]부분합  (0) 2023.09.24
[1753번]최단경로  (0) 2023.09.24
[16928번]뱀과 사다리 게임  (0) 2023.09.24
[12856번]평범한 배낭  (0) 2023.09.24
[10026번]적록색약  (0) 2023.09.24