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

#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/cdescription.jsp?cid=ACPC2017Day1&pid=C
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1 << 30
ll N, K;
ll ans;
vector<pll> T;
vector<int> f1;
vector<ll> f2;

void solve(ll n, ll k) {
  k++;
  if (k > K)
    return;
  if (T[n].second > k) {
    T[n].second = k;
    f1[n] = 1;
    solve(T[n].first, k);
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ans = 0;
  cin >> N >> K;
  T.resize(N, {0, INF});
  f1.resize(N, 0);
  f2.resize(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> T[i].first;
    if (T[i].first == 0) {
      f1[i] = 1;
    } else {
      T[i].first--;
      f2[T[i].first] = 1;
    }
  }

  for (int i = 0; i < N; i++) {
    if (f2[i] == 0) {
      f1[i] = 1;
      solve(i, 0);
    }
  }
  for (int i = 0; i < N; i++) {
    if (f1[i] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/cdescription.jsp?cid=ACPC2017Day1&pid=C
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1 << 30
ll N, K;
ll ans;
vector<pll> T;
vector<int> S;
vector<ll> A;

void solve(ll n, ll k) {
  if (n == 0)
    return;
  if (T[n].second > k)
    return;
  T[n].second = k;
  if (T[n].first == 0) {
    ans++;
    T[n].first = 1;
  }
  solve(A[n], k - 1);
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ans = 0;
  cin >> N >> K;
  T.resize(N + 1, {0, 0});
  S.resize(N + 1, 0);
  A.resize(N + 1, -1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      ans++;
      T[i] = {1, K};
      S[i] = 1;
    } else {
      S[A[i]] = 1;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (S[i] == 1)
      continue;
    solve(i, K - 1);
  }
  cout << ans << endl;
  return 0;
}
Problem p01933 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main() {

  int N, K;

  scanf("%d %d", &N, &K);

  int *table = new int[N];
  bool *henshin_sareru = new bool[N];
  bool *rule_3_apply = new bool[N];

  for (int i = 0; i < N; i++) {
    scanf("%d", &table[i]);
    henshin_sareru[i] = false;
    rule_3_apply[i] = false;
  }

  int *min_count = new int[N];

  for (int i = 0; i < N; i++)
    min_count[i] = BIG_NUM;

  for (int i = N - 1; i >= 0; i--) {
    if (table[i] > 0) {

      henshin_sareru[table[i] - 1] = true;

      if (henshin_sareru[i] == false) {

        int count = 0, loc = table[i] - 1;

        while (count < K - 1) {

          if (min_count[loc] <= count)
            break;

          min_count[loc] = count;

          rule_3_apply[loc] = true;
          henshin_sareru[loc] = true;

          if (table[loc] == 0)
            break;

          loc = table[loc] - 1;
          count++;
        }
      }
    }
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (table[i] == 0 || henshin_sareru[i] == false || rule_3_apply[i] == true)
      ans++;
  }

  printf("%d\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main() {

  int N, K;

  scanf("%d %d", &N, &K);

  int *table = new int[N];
  bool *henshin_sareru = new bool[N];
  bool *rule_3_apply = new bool[N];

  for (int i = 0; i < N; i++) {
    scanf("%d", &table[i]);
    henshin_sareru[i] = false;
    rule_3_apply[i] = false;
  }

  for (int i = N - 1; i >= 0; i--) {
    if (table[i] > 0) {

      henshin_sareru[table[i] - 1] = true;

      if (henshin_sareru[i] == false) {

        int count = 0, loc = table[i] - 1;

        while (count < K - 1) {

          rule_3_apply[loc] = true;
          henshin_sareru[loc] = true;

          if (table[loc] == 0)
            break;

          loc = table[loc] - 1;
          count++;
        }
      }
    }
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (table[i] == 0 || henshin_sareru[i] == false || rule_3_apply[i] == true)
      ans++;
  }

  printf("%d\\n", ans);

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

#include <bits/stdc++.h>
using namespace std;
int k;
bool y[123456];
vector<pair<int, int>> a;
void ta(int aa, int b) {
  b++;
  if (b > k)
    return;
  if (a[aa].second > b) {
    a[aa].second = b;
    y[aa] = 1;
    ta(a[aa].first, b);
  } else
    return;
}

int main() {
  int n;
  int co = 0;
  cin >> n >> k;
  bool x[123456] = {};
  a = vector<pair<int, int>>(n, pair<int, int>(0, 1234567));
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    if (a[i].first != 0) {
      a[i].first--;
      x[a[i].first] = 1;
    } else {
      y[i] = 1;
    }
  }

  //
  for (int i = 0; i < n; i++) {
    // cout << x[i] << endl;
    if (!x[i]) {
      y[i] = 1;
      ta(i, 0);
    }
  }
  for (int i = 0; i < n; i++) {
    // cout << y[i] << endl;
    if (y[i] == 1) {
      co++;
    }
  }
  cout << co << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int k;
bool y[12345];
vector<pair<int, int>> a;
void ta(int aa, int b) {
  b++;
  if (b > k)
    return;
  if (a[aa].second > b) {
    a[aa].second = b;
    y[aa] = 1;
    ta(a[aa].first, b);
  } else
    return;
}

int main() {
  int n;
  int co = 0;
  cin >> n >> k;
  bool x[12345] = {};
  a = vector<pair<int, int>>(n, pair<int, int>(0, 1234567));
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    if (a[i].first != 0) {
      a[i].first--;
      x[a[i].first] = 1;
    } else {
      y[i] = 1;
    }
  }

  //
  for (int i = 0; i < n; i++) {
    // cout << x[i] << endl;
    if (!x[i]) {
      y[i] = 1;
      ta(i, 0);
    }
  }
  for (int i = 0; i < n; i++) {
    // cout << y[i] << endl;
    if (y[i] == 1) {
      co++;
    }
  }
  cout << co << endl;
  return 0;
}
Problem p01933 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N, K;

  scanf("%d%d", &N, &K);

  set<int> not_replyed;
  set<int> not_replying;
  multimap<int, int> replying;

  FOR1(i, 1, N + 1) { not_replyed.insert(i); }

  FOR1(i, 1, N + 1) {
    int a;
    scanf("%d", &a);
    if (a != 0) {
      replying.insert(make_pair(i, a));
      not_replyed.erase(a);
    } else {
      not_replying.insert(i);
    }
  }

  set<int> displayed(not_replyed);
  set<int> temp(not_replyed);
  FOR(i, K - 1) {
    set<int> temp2;
    for (auto x : temp) {
      using iterator = decltype(replying)::iterator;
      pair<iterator, iterator> ret = replying.equal_range(x);
      for (auto it = ret.first; it != ret.second; it++) {
        if (displayed.find(it->second) == displayed.end()) {
          temp2.insert(it->second);
          displayed.insert(it->second);
        }
      }
    }
    temp = move(temp2);
    // printf("displayed%d:{", i);
    // for (auto x : displayed) {
    //   printf("%d, ", x);
    // }
    // printf("}\\n");
  }
  displayed.insert(not_replying.begin(), not_replying.end());

  printf("%lu\\n", displayed.size());

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N, K;

  scanf("%d%d", &N, &K);

  set<int> not_replyed;
  set<int> not_replying;
  multimap<int, int> replying;

  FOR1(i, 1, N + 1) { not_replyed.insert(i); }

  FOR1(i, 1, N + 1) {
    int a;
    scanf("%d", &a);
    if (a != 0) {
      replying.insert(make_pair(i, a));
      not_replyed.erase(a);
    } else {
      not_replying.insert(i);
    }
  }

  // printf("not_replyed:{");
  // for (auto x : not_replyed) {
  //   printf("%d, ", x);
  // }
  // printf("}\\n");
  // printf("not_replying:{");
  // for (auto x : not_replying) {
  //   printf("%d, ", x);
  // }
  // printf("\\n");

  set<int> displayed(not_replyed);
  FOR(i, K - 1) {
    set<int> temp(displayed);
    for (auto x : temp) {
      using iterator = decltype(replying)::iterator;
      pair<iterator, iterator> ret = replying.equal_range(x);
      for (auto it = ret.first; it != ret.second; it++) {
        displayed.insert(it->second);
      }
    }
    // printf("displayed%d:{", i);
    // for (auto x : displayed) {
    //   printf("%d, ", x);
    // }
    // printf("}\\n");
  }
  displayed.insert(not_replying.begin(), not_replying.end());

  printf("%lu\\n", displayed.size());

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

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define INF (1LL << 40)
using namespace std;
typedef long long ll;

struct state {
  ll v, d;

public:
  bool operator<(const state &s) const { return d > s.d; };
};

ll N, M, S, T, D[100000], A, B;
vector<ll> E[100000];

int main(void) {
  cin >> N >> M >> S >> T;
  S--;
  T--;
  REP(i, 0, N) cin >> D[i];
  REP(i, 0, M) {
    cin >> A >> B;
    A--;
    B--;
    if (A < B)
      E[A].push_back(B);
    if (B < A)
      E[B].push_back(A);
  }

  vector<ll> dp(N, INF);
  priority_queue<state> q;
  q.push((state){S, 0});

  while (q.size()) {
    state c = q.top();
    q.pop();

    // cout << c.v << " " << c.d << endl;

    if (c.d >= dp[c.v])
      continue;
    dp[c.v] = c.d;

    if (c.v == T) {
      cout << c.d << endl;
      return 0;
    }

    if (c.v - 1 >= 0 && dp[c.v - 1] > c.d)
      q.push((state){c.v - 1, c.d});
    for (ll u : E[c.v])
      if (dp[u] > c.d + D[u])
        q.push((state){u, c.d + D[u]});
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define INF (1 << 30)
using namespace std;

struct state {
  int v, d;

public:
  bool operator<(const state &s) const { return d > s.d; };
};

int N, M, S, T, D[100000], A, B;
vector<int> E[100000];

int main(void) {
  cin >> N >> M >> S >> T;
  S--;
  T--;
  REP(i, 0, N) cin >> D[i];
  REP(i, 0, M) {
    cin >> A >> B;
    A--;
    B--;
    if (A < B)
      E[A].push_back(B);
    if (B < A)
      E[B].push_back(A);
  }

  vector<int> dp(N, INF);
  priority_queue<state> q;
  q.push((state){S, 0});

  while (q.size()) {
    state c = q.top();
    q.pop();

    // cout << c.v << " " << c.d << endl;

    if (c.d >= dp[c.v])
      continue;
    dp[c.v] = c.d;

    if (c.v == T) {
      cout << c.d << endl;
      return 0;
    }

    REP(u, 0, c.v) if (dp[u] > c.d) q.push((state){u, c.d});
    for (int u : E[c.v])
      if (dp[u] > c.d + D[u])
        q.push((state){u, c.d + D[u]});
  }
}
Problem p01934 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define fordebug                                                               \\
  int hoge;                                                                    \\
  cin >> hoge;
#define DEKAI 1000000007;
#define INF (1 << 28)
#define int long long
#define double long double
#define floot10 cout << fixed << setprecision(10)
int dp[100100];

signed main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int cost[100100];
  lp(i, n) { cin >> cost[i + 1]; }
  vector<pair<int, int>> v;
  lp(i, m) {
    int a, b;
    cin >> a >> b;
    if (a > t)
      continue;
    if (a < s)
      a = s;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  q.push({0, s});
  lp(i, v.size()) {
    int fr = v[i].first;
    int to = v[i].second;
    while (1) {
      if (q.top().second < fr)
        q.pop();
      else
        break;
    }
    q.push({q.top().first + cost[to], to});
  }
  while (1) {
    if (q.top().second < t)
      q.pop();
    else
      break;
  }
  cout << q.top().first << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define fordebug                                                               \\
  int hoge;                                                                    \\
  cin >> hoge;
#define DEKAI 1000000007;
#define INF (1 << 28)
#define int long long
#define double long double
#define floot10 cout << fixed << setprecision(10)
int dp[100100];

signed main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  int cost[100100];
  lp(i, n) {
    dp[i + 1] = DEKAI;
    cin >> cost[i + 1];
  }
  vector<int> go[100100];
  lp(i, m) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i < b; i++) {
      go[i].push_back(b);
    }
  }
  dp[s] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  q.push({0, s});
  while (!q.empty()) {
    int now = q.top().second;
    int nowc = q.top().first;
    // cout<<now<<endl;
    q.pop();
    if (now >= t) {
      cout << nowc << endl;
      return 0;
    } /*
     for(int i=now-1;i>0;i--){
       int next=i;
       int nexc=nowc+cost[next];
       if(dp[next]<=nexc) continue;
       dp[next]=nexc;
       q.push({nexc,next});
       }*/
    lp(i, go[now].size()) {
      int next = go[now][i];
      int nexc = nowc + cost[next];
      if (dp[next] <= nexc)
        continue;
      dp[next] = nexc;
      q.push({nexc, next});
    }
  }
  return 0;
}
Problem p01934 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define LINF 1LL << 60
struct edge {
  ll u;
  ll v;
  ll cost;
  edge() {}
  edge(ll u, ll v, ll cost) : u(u), v(v), cost(cost) {}
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M, s, t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  vector<ll> d(N);
  for (int i = 0; i < N; i++)
    cin >> d[i];
  vector<vector<edge>> G(N);
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(edge(a, min(b, t), d[b]));
  }
  for (int i = t; i >= 1; i--) {
    G[i].push_back(edge(i, i - 1, 0));
  }

  vector<ll> dist(N, LINF);
  queue<pair<ll, ll>> q;
  q.push({s, s});
  dist[s] = 0;
  if (t < s) {
    cout << 0 << endl;
    return 0;
  }
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    ll n = p.first;
    ll maxn = p.second;
    for (auto e : G[n]) {
      if (e.v < maxn) {
        if (dist[e.v] > dist[e.u]) {
          dist[e.v] = dist[e.u];
          q.push({e.v, maxn});
        }
      } else {
        if (dist[e.v] > dist[e.u] + e.cost) {
          dist[e.v] = dist[e.u] + e.cost;
          q.push({e.v, max(maxn, e.v)});
        }
      }
    }
  }
  cout << dist[t] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1 << 30
struct edge {
  int u;
  int v;
  int cost;
  edge() {}
  edge(int u, int v, int cost) : u(u), v(v), cost(cost) {}
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M, s, t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  vector<ll> d(N);
  for (int i = 0; i < N; i++)
    cin >> d[i];
  vector<vector<edge>> G(N);
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(edge(a, min(b, t), d[b]));
  }
  for (int i = t; i > 0; i--) {
    G[i].push_back(edge(i, i - 1, 0));
  }

  vector<ll> dist(t + 1, INF);
  queue<pair<int, int>> q;
  q.push({s, s});
  dist[s] = 0;
  if (t < s) {
    cout << 0 << endl;
    return 0;
  }
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int n = p.first;
    int maxn = p.second;
    for (auto e : G[n]) {
      if (e.v < maxn) {
        if (dist[e.v] > dist[e.u]) {
          dist[e.v] = dist[e.u];
          q.push({e.v, maxn});
        }
      } else {
        if (dist[e.v] > dist[e.u] + e.cost) {
          dist[e.v] = dist[e.u] + e.cost;
          q.push({e.v, max(maxn, e.v)});
        }
      }
    }
  }
  cout << dist[t] << endl;
  return 0;
}
Problem p01934 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int n, m, s, g, d[SIZE], a, b;
vector<int> way[SIZE];

int main() {

  scanf("%d%d%d%d", &n, &m, &s, &g);

  s--;
  g--;

  for (int i = 0; i < n; i++) {
    scanf("%d", d + i);
  }

  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    way[a].push_back(b);
  }

  queue<int> que;

  int dp[SIZE];

  for (int i = 0; i < n; i++) {
    dp[i] = INF;
  }

  dp[s] = 0;

  priority_queue<pair<int, int>> pq;

  pq.push({0, s});

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < way[i].size(); j++) {
      que.push(way[i][j]);
    }

    while (pq.size() && pq.top().second < i) {
      pq.pop();
    }

    while (pq.size() && que.size()) {
      auto p = que.front();
      que.pop();

      if (dp[p] > -pq.top().first + d[p]) {
        dp[p] = min(dp[p], -pq.top().first + d[p]);
        pq.push({-dp[p], p});
      }
    }
  }

  int ans = INF;

  for (int i = g; i < n; i++) {
    ans = min(ans, dp[i]);
  }

  printf("%d\\n", ans);

  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int n, m, s, g, d[SIZE], a, b;
vector<int> way[SIZE];

int main() {

  scanf("%d%d%d%d", &n, &m, &s, &g);

  s--;
  g--;

  for (int i = 0; i < n; i++) {
    scanf("%d", d + i);
  }

  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    way[a].push_back(b);
  }

  queue<pair<int, int>> que;

  int dp[SIZE];

  for (int i = 0; i < n; i++) {
    dp[i] = INF;
  }

  dp[s] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < way[i].size(); j++) {
      que.push({i, way[i][j]});
    }

    while (que.size()) {
      auto p = que.front();
      que.pop();

      dp[p.second] = min(dp[p.second], dp[i] + d[p.second]);

      cerr << p.first << p.second << endl;
    }
  }

  int ans = INF;

  for (int i = g; i < n; i++) {
    ans = min(ans, dp[g]);
  }

  printf("%d\\n", ans);

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

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

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;

#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
  bool a = l > r;
  if (a)
    l = r;
  return a;
}
template <typename T> inline bool chmax(T &l, T r) {
  bool a = l < r;
  if (a)
    l = r;
  return a;
}

typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e15;
int a[212345];
int b[212345];
LL c[212345];
LL d[212345];
int main() {
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  V dist(N, INF);
  VV g(N);
  REP(i, N) cin >> d[i];
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    c[i] = d[b[i]];
    g[a[i]].pb(i);
  }
  REP(i, N - 1) {
    a[i + M] = i + 1;
    b[i + M] = i;
    c[i + M] = 0;
    g[a[i + M]].pb(i + M);
  }
  dist[s] = 0;
  priority_queue<pair<LL, int>> Q;
  Q.push({0ll, s});
  while (Q.size()) {
    auto q = Q.top();
    Q.pop();
    LL cost = -q.fi;
    int v = q.se;
    if (cost > dist[v])
      continue;
    for (auto &e : g[v]) {
      int u = b[e];
      LL nxtcost = c[e] + cost;
      if (chmin(dist[u], nxtcost)) {
        Q.push({-nxtcost, u});
      }
    }
  }
  cout << dist[t] << endl;
  return 0;
}

Error: 0

Fixed submission:

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

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;

#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
  bool a = l > r;
  if (a)
    l = r;
  return a;
}
template <typename T> inline bool chmax(T &l, T r) {
  bool a = l < r;
  if (a)
    l = r;
  return a;
}

typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e15;
int a[112345];
int b[112345];
LL c[112345];
LL d[112345];
int main() {
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  V dist(N, INF);
  VV g(N);
  REP(i, N) cin >> d[i];
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    c[i] = d[b[i]];
    g[a[i]].pb(i);
  }
  REP(i, N - 1) {
    a[i + M] = i + 1;
    b[i + M] = i;
    c[i + M] = 0;
    g[a[i + M]].pb(i + M);
  }
  dist[s] = 0;
  priority_queue<pair<LL, int>> Q;
  Q.push({0ll, s});
  while (Q.size()) {
    auto q = Q.top();
    Q.pop();
    LL cost = -q.fi;
    int v = q.se;
    if (cost > dist[v])
      continue;
    for (auto &e : g[v]) {
      int u = b[e];
      LL nxtcost = c[e] + cost;
      if (chmin(dist[u], nxtcost)) {
        Q.push({-nxtcost, u});
      }
    }
  }
  cout << dist[t] << endl;
  return 0;
}