diff --git "a/khj20006/202511/19 PGM LV3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" "b/khj20006/202511/19 PGM LV3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" new file mode 100644 index 00000000..c4054868 --- /dev/null +++ "b/khj20006/202511/19 PGM LV3 \352\260\200\354\236\245 \353\250\274 \353\205\270\353\223\234.md" @@ -0,0 +1,34 @@ +```cpp +#include +using namespace std; + +int solution(int n, vector> edge) { + const int INF = 123456; + + vector> graph(n+1); + for(auto e : edge) { + int a = e[0], b = e[1]; + graph[a].push_back(b); + graph[b].push_back(a); + } + + queue> q; + vector dist(n+1, INF); + q.emplace(1,0); + dist[1] = 0; + int mx = 0; + while(!q.empty()) { + auto [n,d] = q.front(); q.pop(); + mx = max(mx, d); + for(int i:graph[n]) if(dist[i] == INF) { + dist[i] = d+1; + q.emplace(i, dist[i]); + } + } + + int ans = 0; + for(int i=1;i<=n;i++) if(dist[i] == mx) ans++; + + return ans; +} +``` \ No newline at end of file