Submission #12401175


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, S;
vector<pair<int,int>> E[50];
int A[101], B[101], C[50], D[50];
ll dist[50][3010];
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
bool vis[50][3010];
ll ans[50];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> S;
    chmin(S, 3000);
	rep(i, 0, M) {
		int u, v; cin >> u >> v; u--; v--;
		cin >> A[i] >> B[i];
		E[u].push_back({ v, i });
		E[v].push_back({ u, i });
	}
	rep(i, 0, N) cin >> C[i] >> D[i];

    rep(i, 0, N) rep(s, 0, 3001) dist[i][s] = infl;
    rep(i, 0, N) rep(s, 0, 3001) vis[i][s] = false;
    rep(i, 0, N) ans[i] = infl;

    min_priority_queue<pair<ll, int>> que;

    dist[0][S] = 0;
    que.push({ 0, 0 * 5010 + S });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll cst = q.first;
        int cu = q.second / 5010;
        int s = q.second % 5010;

        if (vis[cu][s]) continue;
        vis[cu][s] = true;

        chmin(ans[cu], cst);

        fore(p, E[cu]) {
            int to = p.first;
            int i = p.second;
            if (s < A[i]) continue;

            ll cst2 = cst + B[i];
            if (chmin(dist[to][s - A[i]], cst2)) que.push({ dist[to][s - A[i]], to * 5010 + s - A[i] });
        }

        ll cst2 = cst + D[cu];
        int s2 = min(3000, s + C[cu]);
        if (chmin(dist[cu][s2], cst2)) que.push({ dist[cu][s2], cu * 5010 + s2 });
    }

    rep(i, 1, N) printf("%lld\n", ans[i]);
}





Submission Info

Submission Time
Task E - Two Currencies
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 2856 Byte
Status AC
Exec Time 46 ms
Memory 6620 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 5
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All line_1.txt, line_2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
line_1.txt AC 19 ms 5004 KB
line_2.txt AC 14 ms 4868 KB
random_01.txt AC 45 ms 5460 KB
random_02.txt AC 44 ms 6620 KB
random_03.txt AC 46 ms 6408 KB
random_04.txt AC 44 ms 5412 KB
random_05.txt AC 41 ms 5424 KB
random_06.txt AC 42 ms 5552 KB
random_07.txt AC 40 ms 5444 KB
random_08.txt AC 42 ms 5452 KB
random_09.txt AC 38 ms 5448 KB
random_10.txt AC 42 ms 6540 KB
random_11.txt AC 43 ms 5428 KB
random_12.txt AC 41 ms 6524 KB
random_13.txt AC 40 ms 5456 KB
random_14.txt AC 40 ms 5496 KB
random_15.txt AC 35 ms 5140 KB
random_16.txt AC 45 ms 6420 KB
random_17.txt AC 39 ms 6580 KB
random_18.txt AC 38 ms 5532 KB
random_19.txt AC 38 ms 5040 KB
random_20.txt AC 40 ms 5496 KB
sample_01.txt AC 2 ms 3704 KB
sample_02.txt AC 4 ms 3836 KB
sample_03.txt AC 7 ms 3864 KB
sample_04.txt AC 5 ms 3864 KB
sample_05.txt AC 3 ms 3740 KB