samurai123's blog

By samurai123, history, 7 years ago, In English

I was solving SHPATH on spoj LINK. It is direct implementation of dijkstra's algorithm but my code is constantly giving runtime error. The error is always occuring when it is extracting last element from priority queue. Can anybody help and tell the reason ? LINK OF CODE

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

fixed code http://ideone.com/wovGYJ

see to //--->> see ... comments !!!

»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Why do you use VLA (variable length array) ??? — it's extension of GCC, not valid for C++, as know as.

string arr[cities+1]; // cities - is variable, and arr - is variable length array.
vector< pair<int,int>> adjacencylist[cities+1] ;  // adjacencylist also VLA.
//valid for C++
//1. method : dynamic array - std::vector
vector< string > arr(cities + 1);
vector< vector< pair<int, int> > > adjacencylist(cities+1);

//2. method: static array :
string arr[10001]; // 10000 - maximum possible cities number
vector< pair<int, int> > adjacencylist[ 10001]; // 10000 - maximum possible cities number.