# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240320 | arnold518 | 날다람쥐 (JOI14_ho_t4) | C++14 | 329 ms | 24680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N, M, X, H[MAXN+10];
vector<pii> adj[MAXN+10];
struct Queue
{
int v; ll w;
bool operator < (const Queue &p) const { return w<p.w; }
};
ll dist[MAXN+10];
bool vis[MAXN+10];
int main()
{
int i, j;
scanf("%d%d%d", &N, &M, &X);
for(i=1; i<=N; i++) scanf("%d", &H[i]);
for(i=1; i<=M; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
if(w<=H[u]) adj[u].push_back({v, w});
if(w<=H[v]) adj[v].push_back({u, w});
}
priority_queue<Queue> PQ;
PQ.push({1, X});
while(!PQ.empty())
{
Queue now=PQ.top(); PQ.pop();
if(vis[now.v]) continue;
vis[now.v]=1; dist[now.v]=now.w;
for(auto nxt : adj[now.v])
{
if(vis[nxt.first]) continue;
PQ.push({nxt.first, min((ll)H[nxt.first], now.w-nxt.second)});
}
}
if(!vis[N]) printf("-1\n");
else printf("%lld\n", (ll)X+H[N]-2*dist[N]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |