Problem p01269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int, int> F;
typedef pair<F, int> P;
struct edge {
  int to, dis, enemy;
  edge() {}
  edge(int to, int dis, int enemy) : to(to), dis(dis), enemy(enemy) {}
};

int n, m, l, costed[128][128];
vector<vector<edge>> info(128);

void init() {
  for (int i = 0; i < 128; i++) {
    for (int j = 0; j < 128; j++)
      costed[i][j] = INF;
  }
  info.resize(0);
  info.resize(128);
}

void add_info() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  info[a].push_back(edge(b, c, d));
  info[b].push_back(edge(a, c, d));
}

int Dijkstra() {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(F(0, 1), l));
  costed[1][l] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int now = p.fr.sc, en = p.fr.fr, mo = p.sc;
    if (now == n)
      return en;
    for (int i = 0; i < info[now].size(); i++) {
      edge e = info[now][i];
      if (e.enemy + en < costed[e.to][mo]) {
        que.push(P(F(e.enemy + en, e.to), mo));
        costed[e.to][mo] = e.enemy + en;
      }
      if (e.enemy == 0) {
        if (en < costed[e.to][mo]) {
          que.push(P(F(en, e.to), mo));
          costed[e.to][mo] = en;
        }
      }
      if (e.dis <= mo) {
        if (en < costed[e.to][mo - e.dis]) {
          que.push(P(F(en, e.to), mo - e.dis));
          costed[e.to][mo - e.dis] = en;
        }
      }
    }
  }
}

int main() {
  while (cin >> n >> m >> l, n || m || l) {
    init();
    for (int i = 0; i < m; i++)
      add_info();
    cout << Dijkstra() << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int, int> F;
typedef pair<F, int> P;
struct edge {
  int to, dis, enemy;
  edge() {}
  edge(int to, int dis, int enemy) : to(to), dis(dis), enemy(enemy) {}
};

int n, m, l, costed[128][128];
vector<vector<edge>> info(128);

void init() {
  for (int i = 0; i < 128; i++) {
    for (int j = 0; j < 128; j++)
      costed[i][j] = INF;
  }
  info.resize(0);
  info.resize(128);
}

void add_info() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  info[a].push_back(edge(b, c, d));
  info[b].push_back(edge(a, c, d));
}

int Dijkstra() {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(F(0, 1), l));
  costed[1][l] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int now = p.fr.sc, en = p.fr.fr, mo = p.sc;
    if (now == n)
      return en;
    for (int i = 0; i < info[now].size(); i++) {
      edge e = info[now][i];
      if (e.enemy + en < costed[e.to][mo]) {
        que.push(P(F(e.enemy + en, e.to), mo));
        costed[e.to][mo] = e.enemy + en;
      }
      if (e.enemy == 0) {
        if (en < costed[e.to][mo]) {
          que.push(P(F(en, e.to), mo));
          costed[e.to][mo] = en;
        }
      }
      if (e.dis <= mo) {
        if (en < costed[e.to][mo - e.dis]) {
          que.push(P(F(en, e.to), mo - e.dis));
          costed[e.to][mo] = en;
        }
      }
    }
  }
}

int main() {
  while (cin >> n >> m >> l, n || m || l) {
    init();
    for (int i = 0; i < m; i++)
      add_info();
    cout << Dijkstra() << endl;
  }
}