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

#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

const long long INF = 10000000000ll;

typedef pair<long long, int> pli;

vector<int> g[100000];
int dang[100000];
bool zombie[100000];

int main() {
  int n, m, k, s;
  long long p, q;
  cin >> n >> m >> k >> s;
  cin >> p >> q;

  priority_queue<pli> que; // ttl, v;

  REP(i, k) {
    int c;
    scanf("%d", &c);
    c--;
    zombie[c] = true;
    que.push(pli(s, c));
  }

  REP(i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  fill(dang, dang + n, -1);
  while (!que.empty()) {
    pli now = que.top();
    que.pop();

    int pos = now.second;
    int ttl = now.first;

    if (dang[pos] >= ttl)
      continue;
    dang[pos] = ttl;

    REP(i, g[pos].size())
    que.push(pli(ttl - 1, g[pos][i]));
  }
  dang[0] = -1;
  dang[n - 1] = -1;

  // dijkstra
  vector<long long> d(n, INF);
  priority_queue<pli, vector<pli>, greater<pli>> que2;
  que2.push(pli(0, 0)); // cost, v

  while (!que2.empty()) {
    pli now = que2.top();
    que2.pop();

    int pos = now.second;
    long long cost = now.first;

    if (d[pos] <= cost)
      continue;
    d[pos] = cost;

    REP(i, g[pos].size()) {
      int to = g[pos][i];

      if (zombie[to])
        continue;

      if (dang[to] != -1)
        que2.push(pli(cost + q, to));
      else
        que2.push(pli(cost + p, to));
    }
  }
  d[n - 1] -= p;

  cout << d[n - 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

const long long INF = 10000000000ll;

typedef pair<long long, int> pli;

vector<int> g[100000];
int dang[100000];
bool zombie[100000];

int main() {
  int n, m, k, s;
  long long p, q;
  cin >> n >> m >> k >> s;
  cin >> p >> q;

  priority_queue<pli> que; // ttl, v;

  REP(i, k) {
    int c;
    scanf("%d", &c);
    c--;
    zombie[c] = true;
    que.push(pli(s, c));
  }

  REP(i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  fill(dang, dang + n, -1);
  while (!que.empty()) {
    pli now = que.top();
    que.pop();

    int pos = now.second;
    int ttl = now.first;

    if (dang[pos] >= ttl)
      continue;
    dang[pos] = ttl;

    REP(i, g[pos].size())
    que.push(pli(ttl - 1, g[pos][i]));
  }
  dang[0] = -1;
  dang[n - 1] = -1;

  // dijkstra
  vector<long long> d(n, INF);
  que.push(pli(0, 0)); // cost, v

  while (!que.empty()) {
    pli now = que.top();
    que.pop();

    int pos = now.second;
    long long cost = now.first;

    if (d[pos] <= cost)
      continue;
    d[pos] = cost;

    REP(i, g[pos].size()) {
      int to = g[pos][i];

      if (zombie[to])
        continue;

      if (dang[to] != -1)
        que.push(pli(cost + q, to));
      else
        que.push(pli(cost + p, to));
    }
  }
  d[n - 1] -= p;

  cout << d[n - 1] << endl;
  return 0;
}