Skip to content

Commit

Permalink
add 2606, 10870
Browse files Browse the repository at this point in the history
2606 바이러스(DFS)
10870 피보나치수5(재귀)
  • Loading branch information
witheunjin committed Apr 25, 2020
1 parent 0d3f979 commit bb0ddc8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
13 changes: 13 additions & 0 deletions BaekJoon/10870_피보나치수5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
using namespace std;

int fibo(int n) {
if(n==0||n==1) return n;
return fibo(n-1) + fibo(n-2);
}
int main(){
int n;
cin>>n;
cout<<fibo(n);
return 0;
}
37 changes: 37 additions & 0 deletions BaekJoon/2606_바이러스.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> adj;
vector<bool> visited;
int count = 0;

void dfs(int here) {
visited[here] = true;
for(int i=0; i<adj[here].size(); ++i) {
int there = adj[here][i];
if(!visited[there]){
++count;
dfs(there);
}
}
}
int main(void) {
int computer = 0;
int pair = 0;
cin>>computer;
cin>>pair;
adj.resize(computer);
visited.resize(computer);
for(int i=0;i<pair;++i) {
int start=0;
int end=0;
cin>>start>>end;
--start; --end;
adj[start].push_back(end);
adj[end].push_back(start);
}
dfs(0);
cout<<count;
return 0;
}
4 changes: 2 additions & 2 deletions BaekJoon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ https://www.acmicpc.net/
|**10998**|**A\*B**|2020.03.26|1|
|**1008**|**A/B**|2020.03.26|5|
|**10869**|**사칙연산**|2020.03.26|1|
|****|****|||
|****|****|||
|**2606**|**바이러스**|2020.04.24|2|
|**10870**|**피보나치수5**|2020.04.25|1|
|****|****|||
|****|****|||
|****|****|||
Expand Down

0 comments on commit bb0ddc8

Please sign in to comment.