Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя samurai123

Автор samurai123, история, 8 лет назад, По-английски

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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

fixed code http://ideone.com/wovGYJ

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

»
8 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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.