编程语言
首页 > 编程语言> > 算法模板

算法模板

作者:互联网

1.最短路
int dijkstra()
{
    // chushihua
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    for (int i = 1; i < n; i++)
    {
        int t = -1;
        for (int j = 1; j < n; j++)
            if (!found[j] && (t == -1 || dist[j] < dist[t]))
                t = j;
        found[t] = 1;
        for (int j = 1; j < n; j++)
            dist[j] = min(dist[j], dist[t] + w[t - 1][j - 1]);
    }
    // for (int i = 1; i < n; i++)
    //     cout << dist[i] << ' ';
    // cout << endl;
    return dist[n - 1];
}

 

标签:0x3f,dist,cout,int,++,算法,found,模板
来源: https://www.cnblogs.com/BGM-WCJ/p/15940534.html