Skip to content

Commit

Permalink
2606 바이러스 / DFS
Browse files Browse the repository at this point in the history
  • Loading branch information
cjy8922 authored Mar 28, 2021
1 parent cddaedf commit 59c776c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 2021_03/BJ_2606.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

vector<int> map[101];
bool check[101];
int res = 0;

void solution(int n) {
for (int i = 0; i < map[n].size(); i++) {
if (!check[map[n][i]]) {
check[map[n][i]] = true;
res++;
solution(map[n][i]);
}
}
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int size, n;
cin >> size >> n;
memset(check, false, sizeof(check));

for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
map[a].push_back(b);
map[b].push_back(a);
}

check[1] = true;
solution(1);
cout << res << endl;
return 0;
}

0 comments on commit 59c776c

Please sign in to comment.