본문 바로가기
백준

C++ 2606 바이러스

by 안선생 2023. 2. 14.
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
#include <iostream>
#include <vector>
#include<queue>
#include<algorithm>
using namespace std;
 
bool v[101={};
vector<int> g[101={};
int aaa = 0;
int dfs(int x)
{
    aaa++;
    v[x] = true;
    for (int i = 0; i < g[x].size(); i++)
    {
        int y = g[x][i];
        if (!v[y])
            dfs(y);
    }
    return aaa;
}
 
int main(void)
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
 
    cout << dfs(1)-1;
   
}
cs

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

 

2606번: 바이러스

첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어

www.acmicpc.net

 

'백준' 카테고리의 다른 글

C++ 11724 연결 요소의 개수  (0) 2023.02.16
C++ 2667 단지번호붙이기  (0) 2023.02.15
C++ 7568 덩치  (0) 2023.02.12
C++ 1927 최소힙  (0) 2023.02.12
C++ 11279 최대 힙  (0) 2023.02.12