Submission #1087858

# Submission time Handle Problem Language Result Execution time Memory
1087858 2024-09-13T10:24:15 Z akim9905 None (JOI14_ho_t4) C++17
100 / 100
119 ms 26064 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;

const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 101010; // PLZ CHK!

int N,M;
ll X,H[MAX],D[MAX],C[MAX];
vector<pll> G[MAX];

typedef array<ll,3> arr;

int main() {
    fio();

    cin>>N>>M>>X;
    for (int i=1; i<=N; i++) cin>>H[i];
    for (int i=0; i<M; i++) {
        int u,v,w; cin>>u>>v>>w;
        if (w<=H[u]) G[u].pb({v,w});
        if (w<=H[v]) G[v].pb({u,w});
    }

    fill(D,D+N+10,LINF);
    
    priority_queue<arr,vector<arr>,greater<arr>> pq;

    D[1]=0; C[1]=X;
    pq.push({D[1],1,C[1]});

    while (!pq.empty()) {
        auto [dst,cur,cht]=pq.top(); pq.pop();
        if (dst!=D[cur]) continue;

        for (auto [nxt,cst]:G[cur]) {
            ll nht=cht-cst,cst2=0;
            if (C[cur]<cst) {
                cst2+=cst-C[cur];
                nht=0;
            }
            if (C[cur]-cst>H[nxt]) {
                cst2+=C[cur]-(H[nxt]+cst);
                nht=H[nxt];
            }
            
            if (D[nxt]>D[cur]+cst+cst2) {
                D[nxt]=D[cur]+cst+cst2;
                C[nxt]=nht;
                pq.push({D[nxt],nxt,C[nxt]});
            }
        }
    }

    // for (int i=1; i<=N; i++) cout<<i<<sp<<D[i]<<sp<<C[i]<<endl;

    cout<<(D[N]==LINF?-1:D[N]+H[N]-C[N]);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2700 KB Output is correct
5 Correct 2 ms 2904 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2928 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2848 KB Output is correct
15 Correct 2 ms 2916 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 16208 KB Output is correct
2 Correct 90 ms 26064 KB Output is correct
3 Correct 72 ms 14848 KB Output is correct
4 Correct 117 ms 25028 KB Output is correct
5 Correct 83 ms 24900 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
7 Correct 52 ms 9752 KB Output is correct
8 Correct 105 ms 22364 KB Output is correct
9 Correct 64 ms 12112 KB Output is correct
10 Correct 41 ms 8276 KB Output is correct
11 Correct 13 ms 4964 KB Output is correct
12 Correct 76 ms 15188 KB Output is correct
13 Correct 26 ms 12884 KB Output is correct
14 Correct 61 ms 11088 KB Output is correct
15 Correct 4 ms 3416 KB Output is correct
16 Correct 112 ms 24092 KB Output is correct
17 Correct 11 ms 4952 KB Output is correct
18 Correct 12 ms 5396 KB Output is correct
19 Correct 31 ms 5968 KB Output is correct
20 Correct 13 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2700 KB Output is correct
5 Correct 2 ms 2904 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2928 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2848 KB Output is correct
15 Correct 2 ms 2916 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 89 ms 16208 KB Output is correct
22 Correct 90 ms 26064 KB Output is correct
23 Correct 72 ms 14848 KB Output is correct
24 Correct 117 ms 25028 KB Output is correct
25 Correct 83 ms 24900 KB Output is correct
26 Correct 5 ms 3160 KB Output is correct
27 Correct 52 ms 9752 KB Output is correct
28 Correct 105 ms 22364 KB Output is correct
29 Correct 64 ms 12112 KB Output is correct
30 Correct 41 ms 8276 KB Output is correct
31 Correct 13 ms 4964 KB Output is correct
32 Correct 76 ms 15188 KB Output is correct
33 Correct 26 ms 12884 KB Output is correct
34 Correct 61 ms 11088 KB Output is correct
35 Correct 4 ms 3416 KB Output is correct
36 Correct 112 ms 24092 KB Output is correct
37 Correct 11 ms 4952 KB Output is correct
38 Correct 12 ms 5396 KB Output is correct
39 Correct 31 ms 5968 KB Output is correct
40 Correct 13 ms 5464 KB Output is correct
41 Correct 69 ms 9292 KB Output is correct
42 Correct 21 ms 6748 KB Output is correct
43 Correct 50 ms 8532 KB Output is correct
44 Correct 46 ms 12112 KB Output is correct
45 Correct 82 ms 23632 KB Output is correct
46 Correct 7 ms 5208 KB Output is correct
47 Correct 101 ms 22224 KB Output is correct
48 Correct 118 ms 23340 KB Output is correct
49 Correct 91 ms 19916 KB Output is correct
50 Correct 87 ms 25256 KB Output is correct
51 Correct 16 ms 5976 KB Output is correct
52 Correct 95 ms 18380 KB Output is correct
53 Correct 57 ms 10276 KB Output is correct
54 Correct 62 ms 12280 KB Output is correct
55 Correct 73 ms 11336 KB Output is correct
56 Correct 119 ms 24012 KB Output is correct
57 Correct 27 ms 8796 KB Output is correct
58 Correct 3 ms 3228 KB Output is correct
59 Correct 52 ms 9812 KB Output is correct
60 Correct 24 ms 8540 KB Output is correct