zoukankan      html  css  js  c++  java
  • Spfa 模板

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    #define INF 0x3F3F3F3F
    using namespace std;
    
    const int MAXN = (int)(1e4 + 10);
    const int MAXM = (int)(1e5 + 10);
    
    int n, ml, md, dist[MAXN];
    int size, head[MAXN], point[MAXM], val[MAXM], nxt[MAXM];
    
    void add (int from, int to, int value)
    {
        val[size] = value;
        point[size] = to;
        nxt[size] = head[from];
        head[from] = size++;
    }
    
    bool  spfa(int s)
    {
        int cnt[MAXN];
        bool vis[MAXN];
        queue<int> q;
        memset(vis, false, sizeof vis);
        memset(dist, 0x3f, sizeof dist);
        memset(time, 0, sizeof time);
        
        q.push(s);
        vis[s] = true;
        dist[s] = 0;
        while(!q.empty()){
            int u = q.front();
            q.pop();
            vis[u] = false;
            for(int i = head[u]; ~i; i = nxt[i]){
                if(dist[point[i]] > dist[u] + val[i]){
                    dist[point[i]] = dist[u] + val[i];
                    if(!vis[point[i]]){
                        vis[point[i]] = true;
                        q.push(point[i]);
                        if(++cnt[point[i]] > n) return false;
                    }
                }
            }
        }
        return true;
    }
  • 相关阅读:
    OSGi for C/C++
    Tizen NPPlugin开发
    Trove4j
    [Tizen]某些目录下存放的东西
    OpenMobile's Application Compatibility Layer (ACL)
    params
    页面无法访问
    websevice 服务前台和后台
    SQL 创建存储过程
    UpdatePanel
  • 原文地址:https://www.cnblogs.com/quasar/p/5140589.html
Copyright © 2011-2022 走看看