zoukankan      html  css  js  c++  java
  • ROADS POJ

      就是在最短路的基础上   多加了一个时间的限制 , 多一个限制多一维就好了  记住 分层最短路要用dijistra !!!  

      

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <cctype>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <bitset>
    #define rap(i, a, n) for(int i=a; i<=n; i++)
    #define rep(i, a, n) for(int i=a; i<n; i++)
    #define lap(i, a, n) for(int i=n; i>=a; i--)
    #define lep(i, a, n) for(int i=n; i>a; i--)
    #define rd(a) scanf("%d", &a)
    #define rlld(a) scanf("%lld", &a)
    #define rc(a) scanf("%c", &a)
    #define rs(a) scanf("%s", a)
    #define pd(a) printf("%d
    ", a);
    #define plld(a) printf("%lld
    ", a);
    #define pc(a) printf("%c
    ", a);
    #define ps(a) printf("%s
    ", a);
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 10010, INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
    int k, n, m;
    int dis[maxn][110], vis[maxn][110], head[maxn];
    int cnt;
    
    struct edge
    {
        int u, v, d, t;
        edge(int u, int v, int d, int t) : u(u), v(v), d(d), t(t) {}
    };
    
    vector<edge> Edge;
    vector<int> G[maxn << 1];
    struct node
    {
        int u, d, t;
        node(int u, int d, int t) : u(u), d(d), t(t) {}
        bool operator < (const node &a) const {
            return d > a.d;
        }
    };
    
    void add(int u, int v, int d, int t)
    {
        Edge.push_back(edge(u, v, d, t));
        G[u].push_back(Edge.size() - 1);
    }
    
    void dijkstra()
    {
        priority_queue<node> Q;
        for(int i = 0; i < maxn; i++) for(int j = 0; j < 110; j++) dis[i][j] = INF;
        mem(vis, 0);
        Q.push(node(1, 0, 0));
        dis[0][1] = 0;
       // vis[0][1] = 1;
        while(!Q.empty())
        {
            node x = Q.top(); Q.pop();
            int u = x.u;
            int t = x.t;
            if(vis[t][u]) continue;
            vis[t][u] = 1;
            for(int i = 0; i < G[u].size(); i++)
            {
                edge e = Edge[G[u][i]];
                if(dis[t + e.t][e.v] > dis[t][u] + e.d && t + e.t <= k)
                {
                    dis[t + e.t][e.v] = dis[t][u] + e.d;
                    Q.push(node(e.v, dis[t + e.t][e.v], t + e.t));
                }
            }
        }
    }
    
    int main()
    {
        int u, v, d, t;
        rd(k), rd(n), rd(m);
        for(int i = 1; i <= m; i++)
        {
            rd(u), rd(v), rd(d), rd(t);
            add(u, v, d, t);
        }
        dijkstra();
        int maxx = INF;
        for(int i = 0; i <= k; i++)
            maxx = min(maxx, dis[i][n]);
        if(maxx == INF)
            return puts("-1"), 0;
        cout << maxx << endl;
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    Echarts数据可视化grid直角坐标系(xAxis、yAxis)
    Cannot find module '@babel/plugin-proposal-class-properties'
    git 基本操作
    React报错:Laravel React-Router browserHistory 刷新子页面报错404
    php报错:Notice: iconv(): Wrong charset, conversion from `GBK' to `UTF8' is not allowed
    Larval报错:后台上传图片,storage目录也有相应的图片,但前台访问不到图片。
    Laravel报错:1071 Specified key was too long; max key length is 1000 bytes
    thinkcmf报错:fileowner(): stat failed for /sys
    vbox虚拟机复制&&虚拟机指定静态IP
    thinkcmf在万网上部署
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9740995.html
Copyright © 2011-2022 走看看