hdu3790 最短路径问题(spfa||dijkstra+两种限制条件)


http://acm.hdu.edu.cn/showproblem.php?pid=3790

题意:多了一个花费的限制条件,距离相等则选花费少的。


思路:直接在原来的判断条件上加就行,不要想太多。注意有重边。


#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

typedef long long LL;

const int N = 1005;
const int INF = 0x3f3f3f3f;

int dis[N], cost[N], G1[N][N], G2[N][N], n;
bool vis[N];

void dijkstra(int s)
{
    for(int i = 1; i <= n; i++)
    {
        dis[i] = INF;
        cost[i] = INF;
    }
    dis[s] = 0;
    cost[s] = 0;
    for(int i = 1; i <= n; i++)
    {
        int k = -1;
        for(int j = 1; j <= n; j++)
        {
            if(!vis[j] && (k==-1 || dis[j]que;
    for(int i = 1; i <= n; i++)
    {
        dis[i] = INF;
        cost[i] = INF;
    }
    dis[s] = 0;
    cost[s] = 0;
    vis[s] = true;
    que.push(s);
    while(!que.empty())
    {
        int now = que.front();
        que.pop();
        vis[now] = false;
        for(int i = 1; i <= n; i++)
        {
            if(dis[now]+G1[now][i]


你可能感兴趣的:(hdu,图论-最短路&差分约束)