{模板}spfa

code:

void spfa()
{
    int h=1,t=1,i,j,k;
    d[1]=1;
    dis[1]=0;
    bz[1]=true;
    while (h<=t)
    {
        int l=d[h];
        i=g[l];//前向新
        while (a[i][0]==l)
        {
            int x=a[i][1];
            if (a[i][2]+dis[l]<dis[x])
            {
                dis[x]=a[i][2]+dis[l];
                if (bz[x]==false)
                {
                    bz[x]=true;
                    t++;
                    d[t]=x;
                }
            }
            i++;
        }
        bz[l]=false;
        h++;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章