| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 151420 | TadijaSebez | 날다람쥐 (JOI14_ho_t4) | C++11 | 283 ms | 17820 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
const ll inf=9e18;
int h[N],hi[N],n,m,X;
ll dist[N][2];
vector<pair<int,int>> E[N];
void Dijkstra()
{
hi[1]=X;
for(int i=2;i<=n;i++) dist[i][0]=dist[i][1]=inf;
dist[1][0]=0;dist[1][1]=X;
priority_queue<pair<ll,int>> pq;
pq.push({0,1});
pq.push({-X,-1});
while(pq.size())
{
int u=pq.top().second;
ll d=-pq.top().first;
pq.pop();
int t=u<0?1:0;
u=abs(u);
if(dist[u][t]!=d) continue;
int H;
if(t==1) H=0;
else H=hi[u];
for(auto e:E[u])
{
int v=e.first;
int w=e.second;
if(H<=w)
{
int go=w+w-H;
if(dist[v][1]>dist[u][t]+go)
{
dist[v][1]=dist[u][t]+go;
pq.push({-dist[v][1],-v});
}
}
else
{
int go=max(w,H-h[v]);
if(dist[v][0]>dist[u][t]+go)
{
dist[v][0]=dist[u][t]+go;
hi[v]=H-go;
pq.push({-dist[v][0],v});
}
}
}
}
}
int main()
{
scanf("%i %i %i",&n,&m,&X);
for(int i=1;i<=n;i++) scanf("%i",&h[i]);
for(int i=1,u,v,w;i<=m;i++)
{
scanf("%i %i %i",&u,&v,&w);
if(h[u]>=w) E[u].pb({v,w});
if(h[v]>=w) E[v].pb({u,w});
}
Dijkstra();
ll ans=min(dist[n][1]+h[n],dist[n][0]+h[n]-hi[n]);
printf("%lld\n",ans>=inf?-1:ans);
return 0;
}
컴파일 시 표준 에러 (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... | ||||
