编码所有对最短路径时出错 [英] error while coding all-pairs shortest path

查看:84
本文介绍了编码所有对最短路径时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译器说存在错误,但没有任何提示.我找不到的错误在哪里?
感谢您的帮助.

The compiler says errors exist but doesn''t give a clue. Where is the errors I can not find?
Thanks for help.

using namespace std;

const int NOT_A_VERTEX = -1;
void allPairs(vector<vector<int> >& a,
              vector<vector<int> >& d,
              vector<vector<int> >& path);

int main() {
    int numberOfVertex;
    int numberOfRoads;
    int minDist;

    cin >> numberOfVertex;
    cin >> numberOfRoads;
    cin >> minDist;

    vector <vector <int> > a(numberOfVertex, vector<int>(numberOfVertex));
    vector <vector <int> > d(numberOfVertex, vector<int>(numberOfVertex));
    vector <vector <int> > path(numberOfVertex, vector<int>(numberOfVertex));
    for(int c = 0 ; c < numberOfRoads; c++){
        int i, j;
        cin >>i; cin >>j;
        a[i][j] = 1;
    }
    allPairs(a,d,path);
    return 0;
}

void allPairs(vector<vector<int> >& a,
              vector<vector<int> >& d,
              vector<vector<int> >& path){
    int n = a.size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n ; j++){
            d[i][j] = a[i][j];
            path[i][j] = NOT_A_VERTEX;
        }
    }
    for(int k = 0; k < n ; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(d[i][k] + d[k][j] < d[i][j]){
                    d[i][j] = d[i][k] + d[k][j];
                    path[i][j] = k;
                }
            }
        }
    }

}

推荐答案


使用VC2010 Express,您的代码可以编译而不会出现错误或警告.
您的错误可能来自错误的项目设置.
欢呼声,
AR
Hi,
Your code compiles without error or warning with VC2010 express.
Your error could come from bad project settings.
cheers,
AR


我修复了它.我认为它运行良好.最后一步是如何编写路径?

I fixed it.I think this runs well. The last step is how the path is written?

for(int i = 0; i < n; i++){
    for(int j = 0; j < n ; j++){
        if(a[i][j] == 1)
            d[i][j] = a[i][j];
        else
            d[i][j] = INFINITY;
        if(i == j)
            d[i][j] = 0;
        path[i][j] = NOT_A_VERTEX;
    }
}


这篇关于编码所有对最短路径时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆