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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int n, m, l;
vector<vector<pair<int, pair<int, int>>>> graph(101);

int solve() {
  vector<vector<int>> result(101, vector<int>(101, mod));
  // result[i][j] :
  // 1??????i?????§??§?§???????????????????????????????j????????????????????´????\\??????????????????¢?????°
  int ans = mod;
  priority_queue<pair<int, pair<int, int>>> qu;
  // ????????£????????¢?????° / ???????????´??? / ??????
  qu.push(make_pair(0, make_pair(1, l)));
  while (!qu.empty()) {
    int enemnum = -(qu.top()).first;
    int now = ((qu.top()).second).first;
    int restmoney = ((qu.top()).second).second;
    qu.pop();
    if (result[now][restmoney] <= enemnum)
      continue;
    result[now][restmoney] = enemnum;
    if (now == n)
      ans = min(ans, enemnum);
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i].first;
      int d = (graph[now][i].second).first;
      int e = (graph[now][i].second).second;
      if (restmoney >= d)
        qu.push(make_pair(-enemnum, make_pair(next, restmoney - d)));
      qu.push(make_pair(-(enemnum + e), make_pair(next, restmoney)));
    }
  }
  return ans;
}

int main() {
  while (1) {
    cin >> n >> m >> l;
    if (n == 0 && m == 0 && l == 0)
      break;
    for (int i = 0; i < 101; i++) {
      graph[i].clear();
    }
    for (int i = 0; i < m; i++) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      graph[a].push_back(make_pair(b, make_pair(d, e)));
      graph[b].push_back(make_pair(a, make_pair(d, e)));
    }
    cout << solve() << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m, l;
  while (1) {
    cin >> n >> m >> l;
    if (n == 0 && m == 0 && l == 0)
      break;
    vector<vector<pair<int, int>>> touzoku(101);
    vector<vector<pair<int, int>>> money(101);
    int result[101][101];
    // result[i][j]???j????????£???i????????????????????§?????£??????????????°
    memset(result, 1000000, sizeof(result));
    for (int i = 0; i < m; i++) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--;
      b--;
      touzoku[a].push_back(make_pair(b, e));
      touzoku[b].push_back(make_pair(a, e));
      money[a].push_back(make_pair(b, d));
      money[b].push_back(make_pair(a, d));
    }
    result[0][l] = 0;
    priority_queue<pair<int, pair<int, int>>> qu;
    qu.push(make_pair(0, make_pair(0, 0)));
    while (!qu.empty()) {
      int t = (qu.top()).first;
      int nowtown = ((qu.top()).second).second;
      int usedmoney = ((qu.top()).second).first;
      // cout << t << " " << nowtown << " " << usedmoney << endl;
      qu.pop();
      // cout << result[nowtown] << " " << t << endl;
      if (result[nowtown][usedmoney] <= t)
        continue;
      // cout << "hoge" << endl;
      result[nowtown][usedmoney] = t;
      if (nowtown == n - 1)
        continue;
      for (int i = 0; i < money[nowtown].size(); i++) {
        // cout << touzoku[nowtown][i] << endl;
        if (usedmoney + money[nowtown][i].second <= l) {
          qu.push(make_pair(t, make_pair(usedmoney + money[nowtown][i].second,
                                         money[nowtown][i].first)));
        }
        qu.push(make_pair(t + touzoku[nowtown][i].second,
                          make_pair(usedmoney, money[nowtown][i].first)));
      }
    }
    int ans = 10000000;
    for (int i = 0; i < l + 1; i++)
      ans = min(ans, result[n - 1][i]);
    cout << ans << endl;
  }
  return 0;
}