Submission #69153706


Source Code Expand

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <assert.h>
#include <random>
#include <chrono>
#include <ctime>
#include <queue>
#include <functional>
using namespace std;

#define ll long long
const int N = (int)5000 + 5;
const ll oo = (ll)1e18 + 5;
int W[N];
vector<int> g[N];
ll dp[N][N];

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define rand(a, b) uniform_int_distribution<ll>(a, b)(rng)

/*
dp[i] = min cost to reach 1 from i
dp[1] = 0
dp[i][t] = W_i * t + min(dp[j][t+1], j adj to i)
dp[i][0] is what we want!
(i, t) -> (j, t + 1) edge has weight W_i * t
(1, .) is a dead-end with cost 0
Run DFS on this graph starting from 
*/
typedef array<int, 2> vtx;

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i=1;i<=n;++i) {
        g[i].clear();
    }
    for (int i=1;i<=n;++i) cin >> W[i];
    for (int i=2;i<=n;++i) {
        for (int j=0;j<=n;++j) {
            dp[i][j] = oo;
        }
    }
    for (int j=0;j<=n;++j) dp[1][j] = W[1] * 1LL * j;
    for (int i=0;i<m;++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int t=n-1;t>=0;--t) {
        for (int u=2;u<=n;++u) {
            for (auto v : g[u]) {
                dp[u][t] = min(dp[v][t + 1] + W[u] * 1LL * t, dp[u][t]);
            }
        }
    }
    for (int i=1;i<=n;++i) cout << dp[i][0] << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Submission Info

Submission Time
Task F - Eat and Ride
User srikkanthr
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1690 Byte
Status AC
Exec Time 613 ms
Memory 199456 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 51
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3580 KiB
00_sample_01.txt AC 1 ms 3616 KiB
00_sample_02.txt AC 1 ms 3572 KiB
01_random_03.txt AC 91 ms 44656 KiB
01_random_04.txt AC 107 ms 56580 KiB
01_random_05.txt AC 23 ms 13288 KiB
01_random_06.txt AC 86 ms 49180 KiB
01_random_07.txt AC 61 ms 36596 KiB
01_random_08.txt AC 76 ms 36132 KiB
01_random_09.txt AC 7 ms 6104 KiB
01_random_10.txt AC 20 ms 15152 KiB
01_random_11.txt AC 587 ms 199288 KiB
01_random_12.txt AC 585 ms 199408 KiB
01_random_13.txt AC 587 ms 199284 KiB
01_random_14.txt AC 589 ms 199456 KiB
01_random_15.txt AC 590 ms 199312 KiB
01_random_16.txt AC 549 ms 199352 KiB
01_random_17.txt AC 608 ms 199304 KiB
01_random_18.txt AC 588 ms 199192 KiB
01_random_19.txt AC 610 ms 199252 KiB
01_random_20.txt AC 607 ms 199304 KiB
01_random_21.txt AC 546 ms 199368 KiB
01_random_22.txt AC 609 ms 199456 KiB
01_random_23.txt AC 591 ms 199332 KiB
01_random_24.txt AC 611 ms 199280 KiB
01_random_25.txt AC 613 ms 199340 KiB
01_random_26.txt AC 542 ms 199208 KiB
01_random_27.txt AC 604 ms 199188 KiB
01_random_28.txt AC 584 ms 199368 KiB
01_random_29.txt AC 611 ms 199332 KiB
01_random_30.txt AC 607 ms 199332 KiB
01_random_31.txt AC 39 ms 22400 KiB
01_random_32.txt AC 141 ms 63832 KiB
01_random_33.txt AC 16 ms 11112 KiB
01_random_34.txt AC 199 ms 81988 KiB
01_random_35.txt AC 22 ms 12136 KiB
01_random_36.txt AC 124 ms 54696 KiB
01_random_37.txt AC 476 ms 172392 KiB
01_random_38.txt AC 119 ms 55180 KiB
01_random_39.txt AC 33 ms 18020 KiB
01_random_40.txt AC 12 ms 7840 KiB
01_random_41.txt AC 334 ms 141932 KiB
01_random_42.txt AC 299 ms 131848 KiB
01_random_43.txt AC 297 ms 130472 KiB
01_random_44.txt AC 295 ms 129652 KiB
01_random_45.txt AC 330 ms 141304 KiB
01_random_46.txt AC 156 ms 62440 KiB
01_random_47.txt AC 153 ms 62540 KiB
01_random_48.txt AC 608 ms 199316 KiB
01_random_49.txt AC 610 ms 199288 KiB
01_random_50.txt AC 609 ms 199304 KiB