Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
                }
            }
        }
    }

}
Posted
Comments
Henry Minute 17-Dec-10 17:09pm    
Give us a clue! Does the compiler say what the errors are, even if it won't tell you where they are?
volvox21 18-Dec-10 3:53am    
I tried today again and it works fine. I don't know why it gave the error yesterday. In addition, I see that although this code is in my book, some things are missing. It doesn't give error now but also doesn't give the correct solution. How can I fix it? Is there any suggestion?

Hi,
Your code compiles without error or warning with VC2010 express.
Your error could come from bad project settings.
cheers,
AR
 
Share this answer
 
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;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900