Problem p02703 (C++) — buggy submission, verdict: Runtime Error


// Problem : E - Two Currencies
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(), (c).end()
#define LB lower_bound
#define UB upper_bound
#define max3(a, b, c) max(c, max(a, b))
#define min3(a, b, c) min(c, min(a, b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  // no of elements less than
#define FBO find_by_order // iterator pointing kth element;indexing starts from
                          // 0
#define CK3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define CK4(a, b, c, d)                                                        \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl

typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
typedef pair<int, pair<int, int>> PIPI;
typedef map<int, int> MII;
typedef vector<int> VI;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
// int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1, T1 = 0; // cin>>T;
  while (T1++ < T) { // cout<<"Case #"<<T1<<": ";
    int n, m, s;
    cin >> n >> m >> s;
    s = min(s, (int)2500);
    vector<vector<PIPI>> adj(n + 1);
    set<PPII> se;
    VI cr(n + 5), dr(n + 5);
    int dp[n + 5][2505];
    bool vis[n + 5][2505];
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= 2500; j++) {
        dp[i][j] = INF;
        vis[i][j] = false;
      }
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      int a, b;
      cin >> a >> b;
      adj[x].pb({y, {a, b}});
      adj[y].pb({x, {a, b}});
    }
    for (int i = 1; i <= n; i++) {
      cin >> cr[i] >> dr[i];
    }
    se.insert({{0, s}, 1});
    while (se.size() != 0) {
      auto p = *se.begin();
      se.erase(se.begin());
      int v = p.SE;
      int tim = p.FI.FI;
      int cur = p.FI.SE;
      if (vis[v][cur] == true)
        continue;
      vis[v][cur] = true;
      if (cur + cr[v] <= 2500)
        se.insert({{tim + dr[v], cur + cr[v]}, v});
      for (auto it : adj[v]) {
        if (cur >= it.SE.FI) {
          if (dp[it.FI][cur - it.SE.FI] > tim + it.SE.SE) {
            dp[it.FI][cur - it.SE.FI] = tim + it.SE.SE;
            se.insert({{tim + it.SE.SE, cur - it.SE.FI}, it.FI});
          }
        }
      }
    }
    for (int i = 2; i <= n; i++) {
      int min1 = INF;
      for (int i1 = 0; i1 <= 2500; i1++) {
        min1 = min(min1, dp[i][i1]);
      }
      cout << min1 << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:


// Problem : E - Two Currencies
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(), (c).end()
#define LB lower_bound
#define UB upper_bound
#define max3(a, b, c) max(c, max(a, b))
#define min3(a, b, c) min(c, min(a, b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int int
#define OOK order_of_key  // no of elements less than
#define FBO find_by_order // iterator pointing kth element;indexing starts from
                          // 0
#define CK3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define CK4(a, b, c, d)                                                        \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl

typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
typedef pair<int, pair<int, int>> PIPI;
typedef map<int, int> MII;
typedef vector<int> VI;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
// int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1, T1 = 0; // cin>>T;
  while (T1++ < T) { // cout<<"Case #"<<T1<<": ";
    int n, m, s;
    cin >> n >> m >> s;
    vector<vector<PIPI>> adj(n + 1);
    set<PPII> se;
    VI cr(n + 5), dr(n + 5);
    int dp[n + 5][2505];
    bool vis[n + 5][2505];
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= 2500; j++) {
        dp[i][j] = INF;
        vis[i][j] = false;
      }
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      int a, b;
      cin >> a >> b;
      adj[x].pb({y, {a, b}});
      adj[y].pb({x, {a, b}});
    }
    for (int i = 1; i <= n; i++) {
      cin >> cr[i] >> dr[i];
    }
    se.insert({{0, s}, 1});
    while (se.size() != 0) {
      auto p = *se.begin();
      se.erase(se.begin());
      int v = p.SE;
      int tim = p.FI.FI;
      int cur = p.FI.SE;
      if (vis[v][cur] == true)
        continue;
      vis[v][cur] = true;
      if (cur + cr[v] <= 2500)
        se.insert({{tim + dr[v], cur + cr[v]}, v});
      for (auto it : adj[v]) {
        if (cur >= it.SE.FI) {
          if (dp[it.FI][cur - it.SE.FI] > tim + it.SE.SE) {
            dp[it.FI][cur - it.SE.FI] = tim + it.SE.SE;
            se.insert({{tim + it.SE.SE, cur - it.SE.FI}, it.FI});
          }
        }
      }
    }
    for (int i = 2; i <= n; i++) {
      int min1 = INF;
      for (int i1 = 0; i1 <= 2500; i1++) {
        min1 = min(min1, dp[i][i1]);
      }
      cout << min1 << endl;
    }
  }

  return 0;
}