### Vector class problem

Program doesn't run with vector class matrix(
typedef vector<unsigned int> row;
typedef vector<row> matrix;
matrix a(40000, row(40000));
), but it does with normal array matrix(int a[100][100]). The problem is that I need a big matrix, and this is the only solution I found. Does anyone have any idea why the program runs fine with the normal array, whereas it doesn't even enter the main function with the vector class array? Any help would be appreciated. Thanks in advance!
Here's the code:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223`` ``````#include #include #include using namespace std; ifstream in("drumuri.in"); ofstream out("drumuri.out"); unsigned int n,m; //typedef vector row; //typedef vector matrix; //matrix a(40000, row(40000)); int a[100][100]; int main(); void op1(unsigned int i, unsigned int j); void op2(unsigned int i, unsigned int j); void op3(unsigned int i, unsigned int d); void op4(unsigned int i); vector capete(unsigned int i); int main() { in>>n>>m; unsigned int i,k,l; int j; for (i=1;i<=m;i++) { in>>j; if(j-4) in>>k>>l; else in>>k; if(j==1) op1(k-1,l-1); if(j==2) op2(k-1,l-1); if(j==3) op3(k-1,l); if(j==4) op4(k-1); } for(i=0;i capete(unsigned int i) { vector capat; vector v,v1,v2; int nr=1; unsigned int k; for (k=0;k capat; int v1=0,v2=0; unsigned int k; for (k=0;k=2||v2>=2) { out<<0< v,v1,v2; int nr=1; unsigned int k; for (k=0;k capat; capat=capete(i); if (capat.size()==1) out<<1<<" "<
Last edited on
Please use code tags (select the code and press the <> button), this is illegible.
sorry, I'm new
You request at least 40,000*40,000*4 = 6.4GB of memory.
Do you use 64bit OS, does your application is 64bit? In 32bit mode you can address just 2GB (or maybe 4Gb) of memory.

BTW, why do you need so heavy construct?
I have windows 8 64 bit, visual studio 2012 64 bit.
It's a graph problem.
First you read two numbers, N and M. N is the size of the graph(the number of nodes) and M is the number of operations you need to read from the file and apply to the graph(initially there are no edges in the graph, just nodes). There are 4 kinds of operations: the first one adds an edge, the second one removes an edge, the third one displays all the nodes that are at a distance D from the node specified, and the fourth one lists the end nodes of the road(one edge cannot have more than two neighbors, and there cannot be any cycles in the graph). And the restrictions are:
• 1 ≤ N ≤ 40000
• 1 ≤ M ≤ 400000
• 0 ≤ D ≤ N-1
• 1 ≤ i,j ≤ N
P.S.: the first three operations have two parameters(for the first two it's the nodes, for the third one it's the node and the distance) and the fourth one only has one parameter(the node that's part of the road)
Also, maximum execution time is 6.5 seconds, available memory is 64 MB, source max size is 20 KB and for 40% of the tests N≤5000 and M≤20000.
It means that you cannot have more than M edges.
You may use different representation of the graph, e.g. adjacency list.

If you still want to use adjacency matrix, you can switch to `bool` instead of `int`.

All above advises are valid if the problem arises because of huge amount of allocated memory.

What is exact wording of the error message?
There is no error message, it opens the console and runs and runs and runs(haven't waited for it to stop, it would probably take a lot of time), but if I include <iostream> and put a cout<<1; at the beginning of the main function, it doesn't show 1 in the console, it still stays blank. There is no error, but it doesn't seem to work(or at least it takes too long to declare the matrix, if that's even possible).
`cout<<1;` doesn't print immediately on the screen.
Try to use
`cout<<1 << endl;` or
 ``12`` ``````cout<<1; cout.flush();``````

I revised the code(had some mistakes in it), tried replacing `int` with `bool`, still doesn't work with the vector class matrix. I also read the page on graph structures, didn't help much... are you suggesting I use something else to define the graph?(other than the adjacency matrix)