Submission #1087837

#TimeUsernameProblemLanguageResultExecution timeMemory
1087837akim9905날다람쥐 (JOI14_ho_t4)C++17
25 / 100
117 ms26572 KiB
#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]; vector<pll> G[MAX]; 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; G[u].pb({v,w}), G[v].pb({u,w}); } fill(D,D+N+10,LINF); priority_queue<pll,vector<pll>,greater<pll>> pq; D[1]=0; pq.push({D[1],1}); while (!pq.empty()) { auto [dst,cur]=pq.top(); pq.pop(); if (dst!=D[cur]) continue; for (auto [nxt,cst]:G[cur]) { if (D[nxt]>D[cur]+cst*2 && H[cur]>=cst) { D[nxt]=D[cur]+cst*2; pq.push({D[nxt],nxt}); } } } cout<<(D[N]==LINF?-1:D[N]+H[N]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...