Submission #69126808


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
#define fs first 
#define sc second
#define sz(x) (x).size()
#define mkp make_pair
#define pb push_back
using pll = pair<ll,ll>;
#pragma GCC optimize("Ofast")

int seed = 114514;
int n, m, cnt[5100] = {0}, W[5100];
ll ans[5100], www[5100];
vector<ll> e[5100];
set<ll> st[5100];

void solve() {
    cin >> n >> m;
    for (int i =1; i <= n; i++) cin >> W[i];
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    memset(ans, 63, sizeof(ans));
    memset(www, 63, sizeof(www));
    ans[1] = 0;
    priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> pq;
    pq.push({0,{0,1}});
    while (pq.size()) {
        auto [dis, p] = pq.top(); pq.pop();
        auto [w, id ] = p;
        if (cnt[id] > 5001) continue;
        cnt[id]++;
        if (w >= www[id]) continue;
        www[id] = min(www[id], w);
        ans[id] = min(ans[id], dis);
        for (int j : e[id]) {
            ll nw = w + W[id];
            ll ndis = dis + nw;
            if (cnt[j] <= 5001 and nw<=www[j]) {
                pq.push(mkp(ndis, mkp(nw, j)));
            } 
        }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    solve();
}

Submission Info

Submission Time
Task F - Eat and Ride
User weakweakweak
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1454 Byte
Status AC
Exec Time 4 ms
Memory 4388 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 3792 KiB
00_sample_01.txt AC 1 ms 3740 KiB
00_sample_02.txt AC 1 ms 3808 KiB
01_random_03.txt AC 2 ms 4096 KiB
01_random_04.txt AC 2 ms 4044 KiB
01_random_05.txt AC 2 ms 4104 KiB
01_random_06.txt AC 2 ms 4020 KiB
01_random_07.txt AC 2 ms 3976 KiB
01_random_08.txt AC 3 ms 4220 KiB
01_random_09.txt AC 2 ms 3984 KiB
01_random_10.txt AC 2 ms 3864 KiB
01_random_11.txt AC 3 ms 4148 KiB
01_random_12.txt AC 3 ms 4152 KiB
01_random_13.txt AC 3 ms 4120 KiB
01_random_14.txt AC 3 ms 4196 KiB
01_random_15.txt AC 3 ms 3992 KiB
01_random_16.txt AC 3 ms 4212 KiB
01_random_17.txt AC 3 ms 4056 KiB
01_random_18.txt AC 3 ms 4388 KiB
01_random_19.txt AC 2 ms 4108 KiB
01_random_20.txt AC 3 ms 4120 KiB
01_random_21.txt AC 3 ms 4140 KiB
01_random_22.txt AC 2 ms 4108 KiB
01_random_23.txt AC 3 ms 4196 KiB
01_random_24.txt AC 2 ms 4124 KiB
01_random_25.txt AC 2 ms 4040 KiB
01_random_26.txt AC 3 ms 4236 KiB
01_random_27.txt AC 2 ms 4112 KiB
01_random_28.txt AC 3 ms 4148 KiB
01_random_29.txt AC 3 ms 4076 KiB
01_random_30.txt AC 3 ms 4024 KiB
01_random_31.txt AC 2 ms 4284 KiB
01_random_32.txt AC 3 ms 4240 KiB
01_random_33.txt AC 2 ms 4228 KiB
01_random_34.txt AC 3 ms 4212 KiB
01_random_35.txt AC 3 ms 4176 KiB
01_random_36.txt AC 3 ms 4104 KiB
01_random_37.txt AC 3 ms 4096 KiB
01_random_38.txt AC 3 ms 4204 KiB
01_random_39.txt AC 2 ms 3996 KiB
01_random_40.txt AC 2 ms 4164 KiB
01_random_41.txt AC 4 ms 4300 KiB
01_random_42.txt AC 4 ms 4304 KiB
01_random_43.txt AC 4 ms 4212 KiB
01_random_44.txt AC 4 ms 4220 KiB
01_random_45.txt AC 4 ms 4084 KiB
01_random_46.txt AC 2 ms 4156 KiB
01_random_47.txt AC 2 ms 4252 KiB
01_random_48.txt AC 2 ms 4116 KiB
01_random_49.txt AC 2 ms 4116 KiB
01_random_50.txt AC 2 ms 4108 KiB