# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
240320 | arnold518 | 날다람쥐 (JOI14_ho_t4) | C++14 | 329 ms | 24680 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
컴파일 시 표준 에러 (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... |