-
algospot - galleryAlgorithm/알고스팟 2020. 1. 20. 05:44123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475//알고스팟 - GALLERY#include <iostream>#include <vector>using namespace std;int V, E;vector<vector<int>> adj;vector<bool> discovered;int ans;void init(){ans = 0;cin >> V >> E;adj = vector<vector<int>>(V);discovered = vector<bool>(V, false);int x, y;for (int i = 0; i < E; i++){cin >> x >> y;adj[x].push_back(y);adj[y].push_back(x);}}//2:cctv 1:watch 0:noneint dfs(int here, bool isRoot){discovered[here] = true;int there;bool isC = false;int ret = 0;int size = adj[here].size();if(isRoot && !size) return 0;for (int i = 0; i < size; i++){there = adj[here][i];if (!discovered[there]){int flag = dfs(there, false);if (!flag)isC = true;else if (flag == 2)ret = 1;}}if (isC){++ans;ret = 2;}return ret;}void dfsAll(){for (int i = 0; i < V; i++)if (!discovered[i])if(!dfs(i, true))++ans;}int main(){ios_base::sync_with_stdio(0); cin.tie(0);int C;cin >> C;for (int t_num = 0; t_num < C; t_num++){init();dfsAll();cout << ans << endl;}}
cs https://algospot.com/judge/problem/read/GALLERY#
algospot.com :: GALLERY
감시 카메라 설치 문제 정보 문제 전세계의 유명한 인물화들을 모아 두는 미술관에 괴도 콩의 도전장이 날아들었습니다. 2022년 2월 2일을 기념하여, 미술관에 전시된 인물화 중 하나의 얼굴을 모 프로게이머의 얼굴로 합성하겠다는 것입니다. 미술관의 관장을 맡고 있는 재하는 이와 같은 사태를 방지하기 위해 감시 카메라를 설치하기로 마음먹었습니다. 미술관은 여러 개의 갤러리와 이들을 연결하는 복도로 구성되어 있으며, 한 갤러리에 감시 카메라를 설치하면 이 갤러
algospot.com
트리를 이용했습니다.
자식노드들의 상태(무방비, 감시중, cctv설치)를 파악해 부모노드에 cctv가 필요한지 아닌지 확인했습니다.
'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - firetrucks (0) 2020.01.20 algospot - clocksync (0) 2020.01.20 algospot - hanoi4 (0) 2020.01.17 algospot - picnic (0) 2020.01.17 algospot - boardcover (0) 2020.01.17