-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2606.cpp
More file actions
64 lines (50 loc) · 1.03 KB
/
2606.cpp
File metadata and controls
64 lines (50 loc) · 1.03 KB
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
/*
작성자: 박진현
문제 : 백준 2606번, 웜 바이러스 문제
*/
#include <stdio.h>
#include <stdlib.h>
int ** computers;
int * visit;
int vCount;
int eCount;
int cnt = 0;
void warmVirus(int start) {
visit[start] = 1;
cnt++;
for (int i = 0; i < vCount; i++) {
if (computers[start][i] == 1 && visit[i] == 0) {
warmVirus(i);
}
}
}
int main(void) {
/*
0 1 0 0 1 0 0
1 0 1 0 1 0 0
0 1 0 0 0 0 0
0 0 0 0 0 0 1
1 1 0 0 0 1 0
0 0 0 0 1 0 0
0 0 0 1 0 0 0
*/
int row, col;
scanf("%d", &vCount); // 7
scanf("%d", &eCount); // 6
computers = (int **)malloc(sizeof(int *) * vCount);
visit = (int *)malloc(sizeof(int) * vCount);
for (int i = 0; i < vCount; i++) {
computers[i] = (int *)malloc(sizeof(int) * vCount);
}
for (int i = 0; i < vCount; i++) {
visit[i] = 0;
}
for (int i = 0; i < eCount; i++) {
scanf("%d %d", &row, &col);
computers[row - 1][col - 1] = 1; // index에 맞춰주기 위하여 -1
computers[col - 1][row - 1] = 1;
}
warmVirus(0);
printf("%d\n", cnt-1);
return 0;
}