alexjercan/bugnet huggingface dataset:
Problem p00545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000005
#define MAX 5001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

pair<ll, int> p[100002];
ll x[1002], d[100002];
int main() {
  ll n, T, Q, t1, t2;
  scanf("%lld%lld%lld", &n, &T, &Q);
  for (int i = 0; i < n; i++) {
    scanf("%lld%d", &p[i].fi, &p[i].se);
  }
  for (int i = 0; i < Q; i++)
    scanf("%lld", &x[i]);

  ll f[2] = {0, 0}, tt;
  for (int i = 0; i < n; i++) {
    if (p[i].se == 1 && f[0] == 0)
      f[0] = 1;
    if (p[i].se == 2 && f[0] == 1) {
      f[1] = (p[i - 1].fi + p[i].fi) / 2;
      tt = i - 1;
      while (tt != -1 && p[tt].se == 1) {
        d[tt] = f[1];
        tt--;
      }
      tt = i;
      while (tt < n && p[tt].se == 2) {
        d[tt] = f[1];
        tt++;
      }
      i = tt;
    }
    if (i == n - 1) {
      tt = i;
      while (tt != -1 && p[tt].se == 1) {
        d[tt] = p[i].fi + T;
        tt--;
      }
    }
    if (p[i].se == 2 && f[0] == 0)
      d[i] = p[i].fi - T;
  }

  // for(int i = 0;i < n;i++)printf("%d ", d[i]);
  ll tmp = 0;
  for (int i = 0; i < Q; i++) {
    tmp = x[i] - 1;
    if (p[tmp].fi < d[tmp])
      d[tmp] = min(p[tmp].fi + T, d[tmp]);
    if (p[tmp].fi > d[tmp])
      d[tmp] = max(p[tmp].fi - T, d[tmp]);
    printf("%lld\\n", d[tmp]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000005
#define MAX 5001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1002][1002];
int dp[1002][1002];
int main() {
  int h, w, n;
  while (1) {
    scanf("%d%d%d", &h, &w, &n);
    if (!h)
      break;
    fill((int *)a, (int *)(a + 1002), 0);
    fill((int *)dp, (int *)(dp + 1002), 0);
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++)
        scanf("%d", &a[i][j]);
    n--;
    dp[1][1] = n;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        dp[i][j] += dp[i][j - 1] / 2;
        if (a[i][j - 1] == 1)
          dp[i][j] += dp[i][j - 1] % 2;
        dp[i][j] += dp[i - 1][j] / 2;
        if (a[i - 1][j] == 0)
          dp[i][j] += dp[i - 1][j] % 2;
      }
    }

    int y = 1, x = 1, t, f;
    while (y <= h && x <= w) {
      f = a[y][x];
      if (dp[y][x] % 2)
        f = !f;
      if (!f)
        y++;
      else
        x++;
    }
    printf("%d %d\\n", y, x);
  }
  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

long long n, q, t;

int d[100000];
long long a[100000], v[1000];

int main() {
  cin >> n >> t >> q;

  for (long long i = 0; i < n; i++)
    cin >> a[i] >> d[i];

  for (long long i = 0; i < q; i++)
    cin >> v[i];

  for (long long i = 0; i < n - 1; i++) {
    if (d[i] == 1 && d[i + 1] == 2) {
      if (a[i + 1] - a[i] <= t * 2) {
        a[i] = a[i] / 2 + a[i + 1] / 2;
        a[i + 1] = a[i];
      } else {
        a[i] += t;
        a[i + 1] -= t;
      }
    }
  }

  long long i = 0;
  while (d[i] == 2) {
    a[i] -= t;
    i++;
  }

  while (i < n - 1) {
    long long j = i;
    while (d[j] == 2 && d[j + 1] == 2) {
      if (a[j + 1] - a[i] <= t)
        a[j + 1] = a[i - 1];
      else
        a[j + 1] -= t;
      j++;
    }
    i = j + 1;
  }

  i = n - 1;
  while (d[i] == 1) {
    a[i] += t;
    i--;
  }

  while (i > -1) {
    long long j = i;
    while (d[j] == 1 && d[j - 1] == 1) {
      if (a[i + 1] - a[j - 1] <= t)
        a[j - 1] = a[i + 1];
      else
        a[j - 1] += t;
      j--;
    }
    i = j - 1;
  }

  for (long i = 0; i < q; i++)
    cout << a[v[i] - 1] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;

int n, q;
long t;

int d[100000], v[100000];
long long a[100000];
bool f[100000];

int main() {
  cin >> n >> t >> q;

  for (int i = 0; i < n; i++)
    cin >> a[i] >> d[i];

  for (int i = 0; i < q; i++)
    cin >> v[i];

  memset(f, 0, sizeof(f));

  for (int j = 0; j < t; j++) {
    for (int i = 0; i < n; i++)
      if (!f[i])
        a[i] += 3 - d[i] * 2;
    for (int i = 0; i < n; i++) {
      if (i < n - 1 && a[i] == a[i + 1]) {
        f[i] = 1;
        f[i + 1] = 1;
      }
    }
  }

  for (int i = 0; i < q; i++)
    cout << a[v[i] - 1] << endl;

  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define INF (1LL << 62)

struct Human {
  int direct;
  long long position;
  long long save;
} human[100001];

int main() {
  long long t;
  int n, q;

  cin >> n >> t >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> human[i].position >> human[i].direct;
  }
  human[0].direct = 1;
  human[0].position = -INF;
  human[n + 1].direct = 2;
  human[n + 1].position = INF;

  for (int i = 0; i <= n; ++i) {
    if (human[i].direct == 1 && human[i + 1].direct == 2) {
      long long d = (human[i].position + human[i + 1].position) / 2;
      for (int j = i; j >= 1 && human[j].direct == 1; --j) {
        human[j].save = d;
      }
      for (int j = i + 1; j <= n && human[j].direct == 2; ++j) {
        human[j].save = d;
      }
    }
  }

  int id;
  for (int i = 0; i < q; ++i) {
    cin >> id;
    if (human[id].direct == 1) {
      cout << (human[id].position + t < human[id].save ? human[id].position + t
                                                       : human[id].save)
           << endl;
    } else {
      cout << (human[id].position - t > human[id].save ? human[id].position - t
                                                       : human[id].save)
           << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

struct Human {
  int direct;
  long long position;
} human[100000];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, t, q;

  cin >> n >> t >> q;
  for (int i = 0; i < n; ++i) {
    cin >> human[i].position >> human[i].direct;
  }

  while (t > 0) {
    int mini = -1;
    long long mind = 1LL << 62;
    for (int i = 0; i < n - 1; ++i) {
      if (human[i].direct != human[i + 1].direct && human[i].direct != 2 &&
          human[i + 1].direct != 1 &&
          mind > human[i + 1].position - human[i].position) {
        mind = human[i + 1].position - human[i].position;
        mini = i;
      }
    }

    if (mini == -1) { //???????????????????????????
      break;
    } else {
      int d;
      if (human[mini].direct == 0 || human[mini + 1].direct == 0) {
        if (t >= mind) {
          d = mind;
        } else {
          d = t;
        }
      } else {
        if (t >= mind / 2) {
          d = mind / 2;
        } else {
          d = t;
        }
      }
      t -= d;

      for (int i = 0; i < n; ++i) {
        if (human[i].direct == 1) {
          human[i].position += d;
        } else if (human[i].direct == 2) {
          human[i].position -= d;
        }
      }

      human[mini].direct = human[mini + 1].direct = 0;
    }
  }

  int id;
  for (int i = 0; i < q; ++i) {
    cin >> id;
    if (human[id].direct == 1) {
      human[id].position += t;
    } else if (human[id].direct == 2) {
      human[id].position -= t;
    }
    cout << human[id - 1].position << endl;
  }

  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll n, t, q, x[100000], a[100000];
int d[100000];
vector<ll> v;

int main() {
  scanf("%lld%lld%lld", &n, &t, &q);
  rep(i, n) scanf("%lld%d", &a[i], &d[i]);
  rep(i, q) scanf("%lld", &x[i]);
  rep(i, n - 1) {
    if (d[i] == 1 && d[i + 1] == 2 && a[i + 1] - a[i] <= t * 2) {
      d[i] = d[i + 1] = 0;
      a[i] = a[i + 1] = (a[i + 1] + a[i]) / 2;
      v.push_back(a[i]);
    }
  }
  rep(i, n) {
    if (!d[i])
      continue;
    ll j = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    if (j < v.size() && d[i] == 1 && v[j] - a[i] <= t) {
      a[i] = v[j];
      d[i] = 0;
    }
    j--;
    if (0 <= j && d[i] == 2 && a[i] - v[j] <= t) {
      a[i] = v[j];
      d[i] = 0;
    }
  }
  rep(j, q) {
    int i = x[j] - 1;
    if (d[i] == 1)
      printf("%lld\\n", a[i] + t);
    else if (d[i])
      printf("%lld\\n", a[i] - t);
    else
      printf("%lld\\n", a[i]);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll n, t, q, x[100000], a[100000];
int d[100000];

int main() {
  scanf("%lld%lld%lld", &n, &t, &q);
  rep(i, n) scanf("%lld%d", &a[i], &d[i]);
  rep(i, q) scanf("%lld", &x[i]);
  rep(i, n - 1) {
    if (d[i] == 1 && d[i + 1] == 2 && a[i + 1] - a[i] <= t * 2) {
      d[i] = d[i + 1] = 0;
      a[i] = a[i + 1] = a[i] + (a[i + 1] - a[i]) / 2;
    }
  }
  rep(i, n) {
    rep(i, n) {
      if (i < n - 1 && d[i] == 1 && !d[i + 1] && a[i + 1] - a[i] <= t) {
        a[i] = a[i + 1];
        d[i] = 0;
      }
      if (0 < i && d[i] == 2 && !d[i - 1] && a[i] - a[i - 1] <= t) {
        a[i] = a[i - 1];
        d[i] = 0;
      }
    }
  }
  rep(j, q) {
    int i = x[j] - 1;
    if (d[i] == 1)
      printf("%lld\\n", a[i] + t);
    else if (d[i])
      printf("%lld\\n", a[i] - t);
    else
      printf("%lld\\n", a[i]);
  }
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error


#include <cstdio>
#include <vector>

using namespace std;

using ll = long long;

const ll inf = 4e18;

ll n, t, q;
ll a[123456];
bool d[123456];
ll x[1000];
vector<ll> talkp;
ll place[123456];

inline ll mean(ll a, ll b) { return a / 2 + b / 2; }

int main() {
  scanf("%lld %lld %lld", &n, &t, &q);
  a[0] = -inf;
  d[0] = true;
  for (int i = 1; i <= n; ++i) {
    int tmpd;
    scanf("%lld %d", a + i, &tmpd);
    d[i] = (tmpd == 1);
  }
  a[n + 1] = inf;
  d[n + 1] = false;
  for (int j = 0; j < q; ++j) {
    scanf("%lld", x + j);
  }
  for (int i = 0; i <= n; ++i) {
    if (d[i] && !d[i + 1]) {
      talkp.push_back(mean(a[i], a[i + 1]));
    }
  }
  auto fritr = talkp.begin();
  auto bkitr = talkp.begin();

  for (int i = 0; i <= n; ++i) {
    place[i] = a[i];
    while (fritr != talkp.end() && (*fritr) < a[i]) {
      bkitr = fritr;
      ++fritr;
    }
    if (d[i]) {
      ll dist = (*fritr) - a[i];
      if (dist < t)
        place[i] += dist;
      else
        place[i] += t;
    } else {
      ll dist = a[i] - (*bkitr);
      if (dist < t)
        place[i] -= dist;
      else
        place[i] -= t;
    }
  }
  for (int j = 0; j < q; ++j) {
    printf("%lld\\n", place[x[j]]);
  }
  return 0;
}

Error: 0

Fixed submission:


#include <cstdio>
#include <vector>

using namespace std;

using ll = long long;

const ll inf = 4e18;

ll n, t, q;
ll a[123456];
bool d[123456];
ll x[1000];
vector<ll> talkp;
ll place[123456];

inline ll mean(ll a, ll b) { return a / 2 + b / 2; }

int main() {
  scanf("%lld %lld %lld", &n, &t, &q);
  a[0] = -inf;
  d[0] = true;
  for (int i = 1; i <= n; ++i) {
    int tmpd;
    scanf("%lld %d", a + i, &tmpd);
    d[i] = (tmpd == 1);
  }
  a[n + 1] = inf;
  d[n + 1] = false;
  for (int j = 0; j < q; ++j) {
    scanf("%lld", x + j);
  }
  for (int i = 0; i <= n; ++i) {
    if (d[i] && !d[i + 1]) {
      talkp.push_back(mean(a[i], a[i + 1]));
    }
  }
  auto fritr = talkp.begin();
  auto bkitr = talkp.begin();

  for (int i = 0; i <= n; ++i) {
    place[i] = a[i];
    while ((*fritr) < a[i]) {
      bkitr = fritr;
      ++fritr;
    }
    if (d[i]) {
      ll dist = (*fritr) - a[i];
      if (dist < t)
        place[i] += dist;
      else
        place[i] += t;
    } else {
      ll dist = a[i] - (*bkitr);
      if (dist < t)
        place[i] -= dist;
      else
        place[i] -= t;
    }
  }
  for (int j = 0; j < q; ++j) {
    printf("%lld\\n", place[x[j]]);
  }
  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int N, Q, flag = 0;
  long long int T, A[100000], D[100000], X[100000];
  scanf("%d %lld %d", &N, &T, &Q);
  for (int i = 1; i <= N; i++) {
    scanf("%lld %lld", &A[i], &D[i]);
  }
  for (int i = 1; i <= Q; i++) {
    scanf("%lld", &X[i]);
  }
  for (int i = 1; i <= Q; i++) {
    if (D[X[i]] == 1) {
      for (int j = X[i] + 1; j <= N; j++) {
        if (D[j] == 2) {
          if ((A[j - 1] + A[j]) / 2 <= A[X[i]] + T) {
            printf("%lld\\n", (A[j - 1] + A[j]) / 2);
            flag = 1;
          }
          break;
        }
      }
      if (flag == 0) {
        printf("%lld\\n", A[X[i]] + T);
      }
    }
    if (D[X[i]] == 2) {
      for (int j = X[i] - 1; j >= 1; j--) {
        if (D[j] == 1) {
          if ((A[j + 1] + A[j]) / 2 >= A[X[i]] - T) {
            printf("%lld\\n", (A[j + 1] + A[j]) / 2);
            flag = 1;
          }
          break;
        }
      }
      if (flag == 0) {
        printf("%lld\\n", A[X[i]] - T);
      }
    }
    flag = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int N, Q, flag = 0;
  long long int T, A[10000], D[10000], X[10000];
  scanf("%d %lld %d", &N, &T, &Q);
  for (int i = 1; i <= N; i++) {
    scanf("%lld %lld", &A[i], &D[i]);
  }
  for (int i = 1; i <= Q; i++) {
    scanf("%lld", &X[i]);
  }
  for (int i = 1; i <= Q; i++) {
    if (D[X[i]] == 1) {
      for (int j = X[i] + 1; j <= N; j++) {
        if (D[j] == 2) {
          if ((A[j - 1] + A[j]) / 2 <= A[X[i]] + T) {
            printf("%lld\\n", (A[j - 1] + A[j]) / 2);
            flag = 1;
          }
          break;
        }
      }
      if (flag == 0) {
        printf("%lld\\n", A[X[i]] + T);
      }
    }
    if (D[X[i]] == 2) {
      for (int j = X[i] - 1; j >= 1; j--) {
        if (D[j] == 1) {
          if ((A[j + 1] + A[j]) / 2 >= A[X[i]] - T) {
            printf("%lld\\n", (A[j + 1] + A[j]) / 2);
            flag = 1;
          }
          break;
        }
      }
      if (flag == 0) {
        printf("%lld\\n", A[X[i]] - T);
      }
    }
    flag = 0;
  }
  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 100100100
typedef long long ll;
typedef pair<int, int> p;

int main(void) {
  int n, q, d[100002];
  ll t, a[100002], stop[100002];
  scanf("%d%lld%d", &n, &t, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%d", &a[i], &d[i]);
  }
  a[0] = -3000000000000000000LL;
  d[0] = 1;
  a[n + 1] = 3000000000000000000LL;
  d[n + 1] = 2;
  for (int i = 0; i <= n; i++) {
    if (d[i] == 1 && d[i + 1] == 2) {
      ll tmp = (a[i] + a[i + 1]) / 2;
      for (int j = i; j >= 0 && d[j] == 1; j--) {
        if (a[j] + t >= tmp)
          stop[j] = tmp;
        else
          stop[j] = a[j] + t;
      }
      for (int j = i + 1; j <= n + 1 && d[j] == 2; j++) {
        if (a[j] - t <= tmp)
          stop[j] = tmp;
        else
          stop[j] = a[j] - t;
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int x;
    scanf("%d", &x);
    printf("%lld\\n", stop[x]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 100100100
typedef long long ll;
typedef pair<int, int> p;

int main(void) {
  int n, q, d[10002];
  ll t, a[10002], stop[10002];
  scanf("%d%lld%d", &n, &t, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%d", &a[i], &d[i]);
  }
  a[0] = -1000000000000000000LL;
  d[0] = 1;
  a[n + 1] = 1000000000000000000LL;
  d[n + 1] = 2;
  for (int i = 0; i <= n; i++) {
    if (d[i] == 1 && d[i + 1] == 2) {
      ll tmp = (a[i] + a[i + 1]) / 2;
      for (int j = i; j >= 0 && d[j] == 1; j--) {
        if (a[j] + t >= tmp)
          stop[j] = tmp;
        else
          stop[j] = a[j] + t;
      }
      for (int j = i + 1; j <= n + 1 && d[j] == 2; j++) {
        if (a[j] - t <= tmp)
          stop[j] = tmp;
        else
          stop[j] = a[j] - t;
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int x;
    scanf("%d", &x);
    printf("%lld\\n", stop[x]);
  }

  return 0;
}
Problem p00545 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

int main() {
  LL N, T, Q;
  cin >> N >> T >> Q;

  vector<LL> A(N), D(N);
  set<LL> s[2];
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> D[i];
    s[--D[i]].emplace(A[i]);
  }
  s[0].emplace(-2e18);
  s[1].emplace(2e18);

  for (auto q = 0; q < Q; ++q) {
    int X;
    cin >> X;
    if (D[--X]) {
      auto x = *--s[0].upper_bound(A[X]);
      auto y = *s[1].upper_bound(x);
      cout << max(A[X] - T, x + (y - x) / 2) << endl;
    } else {
      auto x = *s[1].upper_bound(A[X]);
      auto y = *--s[0].upper_bound(x);
      cout << min(A[X] + T, x - (x - y) / 2) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

int main() {
  int N, T, Q;
  cin >> N >> T >> Q;

  vector<LL> A(N), D(N);
  set<LL> s[2];
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> D[i];
    s[--D[i]].emplace(A[i]);
  }
  s[0].emplace(-2e18);
  s[1].emplace(2e18);

  for (auto q = 0; q < Q; ++q) {
    int X;
    cin >> X;
    if (D[--X]) {
      auto x = *--s[0].upper_bound(A[X]);
      auto y = *s[1].upper_bound(x);
      cout << max(A[X] - T, x + (y - x) / 2) << endl;
    } else {
      auto x = *s[1].upper_bound(A[X]);
      auto y = *--s[0].upper_bound(x);
      cout << min(A[X] + T, x - (x - y) / 2) << endl;
    }
  }
}
Problem p00546 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define INF (1LL << 60)
#define ll long long
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M, K, S;
  cin >> N >> M >> K >> S;
  ll P, Q;
  cin >> P >> Q;
  vector<vector<ll>> G(N + 1);
  vector<ll> cost(N + 1, P);
  vector<bool> kiken(N + 1, false);
  for (int i = 0; i < K; i++) {
    int k;
    cin >> k;
    kiken[k] = true;
    G[0].push_back(k);
    cost[k] = INF;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<pair<ll, ll>> qq;
  qq.push({0, 0});
  vector<bool> f(N + 1, false);
  while (!qq.empty()) {
    auto p = qq.front();
    qq.pop();
    ll s = p.first, n = p.second;
    if (n <= S) {
      for (auto e : G[s]) {
        if (f[e] == false) {
          f[e] = true;
          if (n != 0)
            cost[e] = Q;
          qq.push({e, n + 1});
        }
      }
    }
  }
  vector<ll> dist(N + 1, INF);

  queue<ll> q;
  q.push(1);
  dist[1] = 0;
  while (!q.empty()) {
    auto n = q.front();
    q.pop();
    for (auto e : G[n]) {
      // if (kiken[e] == true)continue;
      if (dist[e] > dist[n] + cost[e]) {
        dist[e] = dist[n] + cost[e];
        q.push(e);
      }
    }
  }
  cout << dist[N] - cost[N] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define INF (1LL << 60)
#define ll long long
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M, K, S;
  cin >> N >> M >> K >> S;
  ll P, Q;
  cin >> P >> Q;
  vector<vector<ll>> G(N + 1, vector<ll>(N + 1));
  vector<ll> cost(N + 1, P);
  vector<bool> kiken(N + 1, false);
  for (int i = 0; i < K; i++) {
    int k;
    cin >> k;
    kiken[k] = true;
    G[0].push_back(k);
    cost[k] = INF;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<pair<ll, ll>> qq;
  qq.push({0, 0});
  vector<bool> f(N + 1, false);
  while (!qq.empty()) {
    auto p = qq.front();
    qq.pop();
    ll s = p.first, n = p.second;
    if (n <= S) {
      for (auto e : G[s]) {
        if (f[e] == false) {
          f[e] = true;
          if (n != 0)
            cost[e] = Q;
          qq.push({e, n + 1});
        }
      }
    }
  }
  vector<ll> dist(N + 1, INF);

  queue<ll> q;
  q.push(1);
  dist[1] = 0;
  while (!q.empty()) {
    auto n = q.front();
    q.pop();
    for (auto e : G[n]) {
      // if (kiken[e] == true)continue;
      if (dist[e] > dist[n] + cost[e]) {
        dist[e] = dist[n] + cost[e];
        q.push(e);
      }
    }
  }
  cout << dist[N] - cost[N] << endl;
}
Problem p00546 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;

int main() {
  ll n, m, k, t, b[2];
  cin >> n >> m >> k >> t >> b[0] >> b[1];
  int c[n];
  ll d[n];
  for (int i = 0; i < n; i++)
    c[i] = 1 << 29, d[i] = INF;
  queue<int> que2;
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    x--;
    c[x] = 0;
    que2.push(x);
  }
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  while (!que2.empty()) {
    int x = que2.front();
    que2.pop();
    for (int i = 0; i < v[x].size(); i++) {
      int y = v[x][i];
      if (c[y] <= c[x] + 1)
        continue;
      c[y] = c[x] + 1;
      que2.push(y);
    }
  }
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, 0));
  d[0] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll x = p.second, cost = p.second;
    if (d[x] < cost)
      continue;
    for (int i = 0; i < v[x].size(); i++) {
      int y = v[x][i];
      ll cc = d[x] + (c[y] > t ? b[0] : b[1]);
      if (!c[y])
        continue;
      if (d[y] > cc) {
        d[y] = cc;
        que.push(P(cc, y));
      }
    }
  }
  cout << d[n - 1] - (c[n - 1] > t ? b[0] : b[1]) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;

int main() {
  ll n, m, k, t, b[2];
  cin >> n >> m >> k >> t >> b[0] >> b[1];
  int c[n];
  ll d[n];
  for (int i = 0; i < n; i++)
    c[i] = 1 << 29, d[i] = INF;
  queue<int> que2;
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    x--;
    c[x] = 0;
    que2.push(x);
  }
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  while (!que2.empty()) {
    int x = que2.front();
    que2.pop();
    for (int i = 0; i < v[x].size(); i++) {
      int y = v[x][i];
      if (c[y] <= c[x] + 1)
        continue;
      c[y] = c[x] + 1;
      que2.push(y);
    }
  }
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, 0));
  d[0] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll x = p.second, cost = p.second;
    if (d[x] < cost)
      continue;
    for (int i = 0; i < v[x].size(); i++) {
      int y = v[x][i];
      ll cc = d[x] + (c[y] > t ? b[0] : b[1]);
      if (!c[y])
        continue;
      if (d[y] >= cc) {
        d[y] = cc;
        que.push(P(cc, y));
      }
    }
  }
  cout << d[n - 1] - (c[n - 1] > t ? b[0] : b[1]) << endl;
  return 0;
}