Submission #55166

# Submission time Handle Problem Language Result Execution time Memory
55166 2018-07-06T07:38:52 Z 윤교준(#1528) None (JOI14_ho_t4) C++11
100 / 100
438 ms 17236 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[2][MAXN];

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

int H[MAXN];

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

void f(int i, int h, ll dst) {
	if(D[h][i] <= dst) return;
	D[h][i] = dst;
	PQ.push(pli(dst, i*2 + h));
}

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[a].eb(b, c);
		if(c <= H[b]) G[b].eb(a, c);
	}

	for(int i = 0; i < 2; i++) fill(D[i], D[i]+N+1, INFLL);
	f(1, !!X, 0);

	for(; !PQ.empty();) {
		int idx, hi; ll dst;
		tie(dst, idx) = PQ.top(); PQ.pop();
		hi = idx&1; idx >>= 1;
		if(D[hi][idx] < dst) continue;
		if(idx == N) {
            if(!hi) {
                upmin(Ans, dst + H[N]);
            } else {
                ll h = ll(X) - dst;
                upmin(Ans, dst + H[N] - h);
            }
            continue;
		}

		for(pii e : G[idx]) {
			int nidx = e.first;
			ll c = e.second;
			if(!hi) {
				ll ndst = dst + c * 2;
				f(nidx, 0, ndst);
			} else {
				ll h = ll(X) - dst;
				ll ndst = INFLL;
				if(H[nidx] < h-c) {
					ndst = dst + h - H[nidx];
					f(nidx, 1, ndst);
				} else if(c < h) {
					ndst = dst + c;
					f(nidx, 1, ndst);
				} else {
					ndst = dst + c * 2 - h;
					f(nidx, 0, ndst);
				}
			}
		}
	}

	if(INFLL <= Ans) puts("-1");
	else cout << Ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 7 ms 2920 KB Output is correct
3 Correct 8 ms 2996 KB Output is correct
4 Correct 6 ms 2996 KB Output is correct
5 Correct 6 ms 2996 KB Output is correct
6 Correct 5 ms 2996 KB Output is correct
7 Correct 7 ms 2996 KB Output is correct
8 Correct 7 ms 3024 KB Output is correct
9 Correct 7 ms 3028 KB Output is correct
10 Correct 7 ms 3116 KB Output is correct
11 Correct 5 ms 3116 KB Output is correct
12 Correct 8 ms 3116 KB Output is correct
13 Correct 7 ms 3116 KB Output is correct
14 Correct 6 ms 3116 KB Output is correct
15 Correct 6 ms 3116 KB Output is correct
16 Correct 6 ms 3116 KB Output is correct
17 Correct 6 ms 3116 KB Output is correct
18 Correct 6 ms 3116 KB Output is correct
19 Correct 5 ms 3116 KB Output is correct
20 Correct 6 ms 3168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 11364 KB Output is correct
2 Correct 229 ms 16448 KB Output is correct
3 Correct 194 ms 16448 KB Output is correct
4 Correct 307 ms 17080 KB Output is correct
5 Correct 241 ms 17080 KB Output is correct
6 Correct 12 ms 17080 KB Output is correct
7 Correct 139 ms 17080 KB Output is correct
8 Correct 359 ms 17080 KB Output is correct
9 Correct 172 ms 17080 KB Output is correct
10 Correct 107 ms 17080 KB Output is correct
11 Correct 31 ms 17080 KB Output is correct
12 Correct 164 ms 17080 KB Output is correct
13 Correct 64 ms 17080 KB Output is correct
14 Correct 174 ms 17080 KB Output is correct
15 Correct 13 ms 17080 KB Output is correct
16 Correct 236 ms 17080 KB Output is correct
17 Correct 27 ms 17080 KB Output is correct
18 Correct 44 ms 17080 KB Output is correct
19 Correct 77 ms 17080 KB Output is correct
20 Correct 36 ms 17080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 7 ms 2920 KB Output is correct
3 Correct 8 ms 2996 KB Output is correct
4 Correct 6 ms 2996 KB Output is correct
5 Correct 6 ms 2996 KB Output is correct
6 Correct 5 ms 2996 KB Output is correct
7 Correct 7 ms 2996 KB Output is correct
8 Correct 7 ms 3024 KB Output is correct
9 Correct 7 ms 3028 KB Output is correct
10 Correct 7 ms 3116 KB Output is correct
11 Correct 5 ms 3116 KB Output is correct
12 Correct 8 ms 3116 KB Output is correct
13 Correct 7 ms 3116 KB Output is correct
14 Correct 6 ms 3116 KB Output is correct
15 Correct 6 ms 3116 KB Output is correct
16 Correct 6 ms 3116 KB Output is correct
17 Correct 6 ms 3116 KB Output is correct
18 Correct 6 ms 3116 KB Output is correct
19 Correct 5 ms 3116 KB Output is correct
20 Correct 6 ms 3168 KB Output is correct
21 Correct 265 ms 11364 KB Output is correct
22 Correct 229 ms 16448 KB Output is correct
23 Correct 194 ms 16448 KB Output is correct
24 Correct 307 ms 17080 KB Output is correct
25 Correct 241 ms 17080 KB Output is correct
26 Correct 12 ms 17080 KB Output is correct
27 Correct 139 ms 17080 KB Output is correct
28 Correct 359 ms 17080 KB Output is correct
29 Correct 172 ms 17080 KB Output is correct
30 Correct 107 ms 17080 KB Output is correct
31 Correct 31 ms 17080 KB Output is correct
32 Correct 164 ms 17080 KB Output is correct
33 Correct 64 ms 17080 KB Output is correct
34 Correct 174 ms 17080 KB Output is correct
35 Correct 13 ms 17080 KB Output is correct
36 Correct 236 ms 17080 KB Output is correct
37 Correct 27 ms 17080 KB Output is correct
38 Correct 44 ms 17080 KB Output is correct
39 Correct 77 ms 17080 KB Output is correct
40 Correct 36 ms 17080 KB Output is correct
41 Correct 194 ms 17080 KB Output is correct
42 Correct 59 ms 17080 KB Output is correct
43 Correct 148 ms 17080 KB Output is correct
44 Correct 182 ms 17080 KB Output is correct
45 Correct 305 ms 17080 KB Output is correct
46 Correct 25 ms 17080 KB Output is correct
47 Correct 438 ms 17080 KB Output is correct
48 Correct 352 ms 17080 KB Output is correct
49 Correct 287 ms 17080 KB Output is correct
50 Correct 272 ms 17080 KB Output is correct
51 Correct 55 ms 17080 KB Output is correct
52 Correct 318 ms 17080 KB Output is correct
53 Correct 156 ms 17080 KB Output is correct
54 Correct 180 ms 17080 KB Output is correct
55 Correct 154 ms 17080 KB Output is correct
56 Correct 349 ms 17236 KB Output is correct
57 Correct 94 ms 17236 KB Output is correct
58 Correct 11 ms 17236 KB Output is correct
59 Correct 196 ms 17236 KB Output is correct
60 Correct 77 ms 17236 KB Output is correct