Algorithm/알고스팟
algospot - gallery
jhg0406
2020. 1. 20. 05:44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
//알고스팟 - 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:none
int 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
Gallery
트리를 이용했습니다.
자식노드들의 상태(무방비, 감시중, cctv설치)를 파악해 부모노드에 cctv가 필요한지 아닌지 확인했습니다.
