Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
bfs.hpp
[詳解]
1
#
pragma
once
2
#
include
"../../../kyopro_library/template.hpp"
3
4
/// @brief 重みなしグラフ g の頂点 start からの最短距離を求める
5
/// @note O(E+V)
6
vector
<
ll
>
BFS
(
const
vector<vector<
int
>>& g,
int
start=0) {
7
int
n=g.size();
8
vector<ll> ret(n,INF); ret[start]=0;
9
queue<
int
> que; que.push(start);
10
11
while
(!que.empty()) {
12
int
now=que.front();que.pop();
13
for
(
int
nxt:g[now])
if
(chmin(ret[nxt],ret[now]+1)) que.push(nxt);
14
}
15
16
return
ret;
17
}
BFS
vector< ll > BFS(const vector< vector< int > > &g, int start=0)
重みなしグラフ g の頂点 start からの最短距離を求める
Definition
bfs.hpp:6
graph
shortest_path
bfs.hpp
構築:
1.13.2