Floyed
for(int k = 1;k <= n;k++){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
f[i][j] = std::min(f[i][j],f[i][k] + f[k][j]);
}
}
}
spfa
queue<int>q;
bool vis[N];
int dis[N];
void spfa(){
fill(dis + 1,dis + n + 1,INT_MAX);
vis[s] = true;
dis[s] = 0;
q.push(s);
while(!q.empty()){
int u = q.front();
vis[u] = false;
q.pop();
for(int i = head[u];i;i = edge[i].next){
int v = edge[i].node;
if(dis[v] > dis[u] +_edge[i].w){
dis[v] = dis[u] + edge[i].w;
if(!vis[v]){
q.push(v);
vis[v] = true;
}
}
}
}
}
dijkstra
typedef pair<int,int> pii;
priority_queue<pii,vector<pii>,greater<pii> >q;
int dis[N];
bool vis[N];
void dijkstra(){
fill(dis + 1,dis + n + 1,INT_MAX);
q.push(std::make_pair(dis[s] = 0,s);
vis[s] = true;
while(!q.empty()){
int u = q.top().second;
q.pop();
if(vis[u]){
continue;
}
vis[u] = 1;
for(int i = head[u];i;i = edge[i].next){
int v = edge[i].node;
if(dis[v] > dis[u] + edge[i].w){
dis[v] = dis[u] + edge[i].w;
q.push(std::make_pair(dis[v],v));
}
}
}
}
Floyed 医院设置
spfa/dijkstra spfa模板题 dijkstra模板题
通往奥格瑞玛的道路
Telephone Lines S
最优贸易
冻结
飞行路线
Revamping Trails G