Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- web
- ๊ทธ๋ฆฌ๋
- ์ฌ๊ท
- ์คํ
- ๋ถํ ์ ๋ณต
- thymeleaf
- Reversing
- ๋ฐฑํธ๋ํน
- ์ฐ์ ์์ ํ
- ๊ตฌํ
- dynamic debugging
- dfs
- error
- ๋งต
- ์ต๋จ ๊ฒฝ๋ก
- ์๋ฎฌ๋ ์ด์
- ๋์ ํฉ
- ์ด๋ถ ํ์
- JPA
- Spring
- ๋ฐ์ดํฌ์คํธ๋ผ
- BFS
- ์์ ์ ๋ ฌ
- GCP
- DP
- c++
- OS
- ๋ฌธ์์ด
- java
- CVE
Archives
- Today
- Total
hades
[Baekjoon] 2606๋ฒ: ๋ฐ์ด๋ฌ์ค ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/2606
๐ ์ค๊ณ
1๋ฒ๊ณผ ์ฐ๊ฒฐ๋ ์ปดํจํฐ๋ค์ด ๊ฐ์ผ๋๋ค๋ ๊ฒ์์ BFS๋ฅผ ํ์ฉํด์ผ ํ๋ค๋ ๊ฒ์ ์ ์ ์๋ค. ๋ฐฉ๋ฌธ ์ฒ๋ฆฌ๋ฅผ ํ์ฌ ์ค๋ณตํด์ ํ์ ๋ด์ง ์๋๋ก ์ค๊ณํ์๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
int n, m, a, b, result=0;
vector<vector<int>> adj_list(101);
vector<bool> visited(101);
queue<int> q;
void bfs(){
visited[1] = true;
q.push(1);
while (!q.empty()){
int x = q.front();
q.pop();
for (int i=0; i<adj_list[x].size(); i++){
int y = adj_list[x][i];
if (!visited[y]){
q.push(y);
visited[y] = true;
result += 1;
}
}
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i=0; i<m; i++){
cin >> a >> b;
adj_list[a].push_back(b);
adj_list[b].push_back(a);
}
bfs();
cout << result << "\n";
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 2667๋ฒ: ๋จ์ง๋ฒํธ๋ถ์ด๊ธฐ (0) | 2024.07.13 |
---|---|
[Baekjoon] 2630๋ฒ: ์์ข ์ด ๋ง๋ค๊ธฐ (0) | 2024.07.11 |
[Baekjoon] 2579๋ฒ: ๊ณ๋จ ์ค๋ฅด๊ธฐ (0) | 2024.07.10 |
[Baekjoon] 2178๋ฒ: ๋ฏธ๋ก ํ์ (0) | 2024.07.10 |
[Baekjoon] 1931๋ฒ: ํ์์ค ๋ฐฐ์ (0) | 2024.07.09 |