diff --git "a/hyeokbini/30206.\354\260\250\353\237\211 \353\260\260\354\271\230/30206.cpp" "b/hyeokbini/30206.\354\260\250\353\237\211 \353\260\260\354\271\230/30206.cpp" new file mode 100644 index 0000000..01219c5 --- /dev/null +++ "b/hyeokbini/30206.\354\260\250\353\237\211 \353\260\260\354\271\230/30206.cpp" @@ -0,0 +1,66 @@ +#include +using namespace std; + +int n, m; +vector> arr; + +int MOD = 1000000007; + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(0); + freopen("test.txt", "rt", stdin); + cin >> n >> m; + arr.resize(n + 1, vector()); + + for (int i = 0; i < m; i++) + { + int a, b; + cin >> a >> b; + arr[a].push_back(b); + arr[b].push_back(a); + } + + // BFS로 레벨(거리) 계산 + vector dist(n + 1, -1); + queue q; + q.push(1); + dist[1] = 0; + + int maxLevel = 0; + vector levelCount(n + 1, 0); + + while (!q.empty()) + { + int u = q.front(); + q.pop(); + + for (int v : arr[u]) + { + if (dist[v] == -1) + { + dist[v] = dist[u] + 1; + levelCount[dist[v]]++; + if (dist[v] > maxLevel) + { + maxLevel = dist[v]; + } + q.push(v); + } + } + } + + // 1번 노드 선택 여부(2가지) × 각 레벨마다 (선택 안함 + 해당 레벨에서 1개 선택) + long long ans = 2; // 1번 노드 포함/미포함 + for (int d = 1; d <= maxLevel; d++) + { + ans = (ans * ((levelCount[d] + 1) % MOD)) % MOD; + } + + // 공집합 제외 + ans = (ans - 1 + MOD) % MOD; + + cout << ans; + return 0; +} diff --git a/hyeokbini/README.md b/hyeokbini/README.md index 182728a..43f1d9f 100644 --- a/hyeokbini/README.md +++ b/hyeokbini/README.md @@ -23,3 +23,4 @@ | 19차시 | 2025.08.10 | 브루트포스 | [리모컨](https://www.acmicpc.net/problem/1107)|[#19](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/68)| | 20차시 | 2025.08.14 | 완전탐색,DFS | [모음사전](https://school.programmers.co.kr/learn/courses/30/lessons/84512)|[#20](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/72)| | 21차시 | 2025.08.19 | 브루트포스 | [제곱수 찾기](https://www.acmicpc.net/problem/1025)|[#21](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/76)| + | 22차시 | 2025.08.22 | 그래프 탐색 | [차량 배치](https://www.acmicpc.net/problem/30206)|[#22](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/77)|