Submission #55147

# Submission time Handle Problem Language Result Execution time Memory
55147 2018-07-06T06:29:21 Z 윤교준(#1528) None (JOI14_ho_t4) C++11
25 / 100
295 ms 75196 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

const int MAXN = 100005;
const int MAXM = 300005;

priority_queue<pli, vector<pli>, greater<pli>> PQ;

vector<pii> G[MAXN];

ll D[MAXN];

int A[MAXM], B[MAXM], C[MAXM];

int H[MAXN];

ll Ans = INFLL;
int N, M, X;

int main() {
    //freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);

	cin >> N >> M >> X;
	for(int i = 1; i <= N; i++) cin >> H[i];
	for(int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i];

	for(int i = 1, a, b, c; i <= M; i++) {
		a = A[i]; b = B[i]; c = C[i];
		if(c <= H[a]) G[b].eb(a, c);
		if(c <= H[b]) G[a].eb(b, c);
	}

	fill(D, D+N+1, INFLL);

	D[N] = 0;
	PQ.push(pli(0, N));

	for(; !PQ.empty();) {
		int idx; ll dst;
		tie(dst, idx) = PQ.top(); PQ.pop();

		if(D[idx] < dst) continue;

		for(pii e : G[idx]) {
			int nidx = e.first;
			ll ndst = dst + e.second;

			if(D[nidx] <= ndst) continue;
			D[nidx] = ndst;
			PQ.push(pli(ndst, nidx));
		}
	}

	if(INFLL <= D[1]) {
		puts("-1");
		return 0;
	}

	for(int i = 1, a, b, c; i <= M; i++) {
		a = A[i]; b = B[i]; c = C[i];
		if(a > b) swap(a, b);
		if(1 != a) continue;
		if(H[1] < c) continue;

		if(X <= H[b]+c) {
			ll t = (D[b] + c) * 2 + H[N] - X;
			upmin(Ans, t);
		} else {
			ll t = (D[b] + c) * 2 + H[N] + X - ll(H[b] + c)*2;
			upmin(Ans, t);
		}
	}

	cout << Ans << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 7 ms 3068 KB Output is correct
3 Correct 7 ms 3068 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 4 ms 3068 KB Output is correct
6 Incorrect 4 ms 3068 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 17488 KB Output is correct
2 Correct 158 ms 28060 KB Output is correct
3 Correct 164 ms 28060 KB Output is correct
4 Correct 234 ms 35124 KB Output is correct
5 Correct 173 ms 39828 KB Output is correct
6 Correct 11 ms 39828 KB Output is correct
7 Correct 135 ms 39828 KB Output is correct
8 Correct 295 ms 49148 KB Output is correct
9 Correct 159 ms 49252 KB Output is correct
10 Correct 98 ms 51476 KB Output is correct
11 Correct 27 ms 51476 KB Output is correct
12 Correct 128 ms 58596 KB Output is correct
13 Correct 63 ms 59832 KB Output is correct
14 Correct 131 ms 63956 KB Output is correct
15 Correct 11 ms 63956 KB Output is correct
16 Correct 237 ms 75196 KB Output is correct
17 Correct 25 ms 75196 KB Output is correct
18 Correct 39 ms 75196 KB Output is correct
19 Correct 73 ms 75196 KB Output is correct
20 Correct 39 ms 75196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 7 ms 3068 KB Output is correct
3 Correct 7 ms 3068 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 4 ms 3068 KB Output is correct
6 Incorrect 4 ms 3068 KB Output isn't correct
7 Halted 0 ms 0 KB -