0

I'm making an adjacency list to represent a graph of roads, there are two kinds of weights (length and capacity) and for some reason this code never exits the for loop. it gets stuck on the cin for the last line. input is in the form:

4 5 4
0 1 1 5
0 2 1 4
1 2 2 2
1 3 1 4
2 3 1 5

I'm a student starting out. Help is very much appreciated thank you.

#include <iostream>
#include <vector>
using namespace std;

int N, M, T; //#cities N, #highways M, time available T

struct Road {
    int Y, L, C; //destination Y, length L and capacity C
};

void readNetwork(vector<vector<Road>> &adjList) {
    cin >> N >> M >> T;
    adjList.resize(N);
    for (int i = 0; i < M; i++){
        int x, y, l, c;
        cin >> x >> y >> l >> c;
        adjList[x].push_back({y,l,c});
    }
}

int main() {
    
    vector<vector<Road>> adjList;

    readNetwork(adjList);
    cout << adjList.size();

    return 0;
};
3
  • How did you determine it got stuck? Did your debugger tell you that? It looks just fine here. Commented Nov 17, 2022 at 21:25
  • is the "/" supposed to be there? i ran your code in the compiler, putting your input in a file without that slash and it outputted "4" Commented Nov 17, 2022 at 21:26
  • It worked for me. I suggest you add some cout statements to print out the values that you read from the cin and also before that to indicate that it's waiting for your input. As a side note, what does the variable T do? And why do you have `` at the end of the input? Commented Nov 17, 2022 at 21:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.