Dijkstra算法
1.找到白点中\(d\)值最小的点,并把该白点标位蓝点
2.更新与该蓝点相邻的其他点的\(d\)值
/*
Coder
Setting sail and crossing the sea,
Can always going through the waves by wind.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 10010
using namespace std;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
bool vis[MAXN];
int d[MAXN];
int G[MAXN][MAXN];
void dijkstra(){
memset(vis,false,sizeof(vis));
memset(d,0x3f,sizeof(d));
d[s]=0;
while(true){
int u=-1;
for(int i=1;i<=n;i++){
if(!vis[i]&&(u==-1||d[i]<d[u])){
u=i;
}
}
if(u==-1) break;
vis[u]=true;
for(int i=1;i<=n;i++){
if(G[u][i]!=0){//u点和i点连通
d[i]=min(d[i],d[u]+G[u][i]);
}
}
}
}
int main(){
return 0;
}
/*
Coder
Setting sail and crossing the sea,
Can always going through the waves by wind.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 10010
using namespace std;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
vector<int> q;
int G[MAXN][MAXN];
void dijkstra(){
memset(vis,false,sizeof(vis));
memset(d,0x3f,sizeof(d));
d[s]=0;
while(true){
int u=-1;
for(int i=1;i<=n;i++){
if(!vis[i]&&(u==-1||d[i]<d[u])){
u=i;
}
}
if(u==-1) break;
vis[u]=true;
for(int i=0;i<G[u].size();i++){
edge e=G[u][i];
d[e.to]=min(d[e.to],d[u]+e.cost);
}
}
}
int main(){
return 0;
}
ICtiger's Blog
求关注
$e^{ix}=cosx+isinx$