Submission #154078

# Submission time Handle Problem Language Result Execution time Memory
154078 2019-09-18T10:09:04 Z mhy908 None (JOI14_ho_t4) C++14
100 / 100
610 ms 34264 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define llinf 8987654321987654321
#define inf 1987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int h[100010];
LL dist[100010];
vector<int> link[100010], c[100010];
int n, m, x;
priority_queue<pair<LL, int> > q;

int main(){
	scanf("%d %d %d",&n, &m, &x);
	for(int i=1; i<=n; i++) scanf("%d", &h[i]);
	for(int i=1; i<=m; i++){
        int a, b, t;
		scanf("%d %d %d", &a, &b, &t);
        link[a].pb(b);
        c[a].pb(t);
        link[b].pb(a);
        c[b].pb(t);
	}
	for(int i=1; i<=n; i++)dist[i]=-llinf;
	q.push({(LL)x, 1});
	while(!q.empty()){
		int now=q.top().S;
		LL dis=q.top().F;
		q.pop();
		if(dist[now]!=-llinf)continue;
      	dist[now]=dis;
		for(int i=0; i<link[now].size(); i++){
			int u=link[now][i], co=c[now][i];
			if(co>h[now])continue;
			q.push({min(dis-co, (LL)h[u]), u});
		}
	}
    //for(int i=1; i<=n; i++)printf("%lld ", dist[i]);
	if(dist[n]==-llinf)puts("-1");
	else printf("%lld", (LL)x+(LL)h[n]-dist[n]*2);
}

Compilation message

2014_ho_t4.cpp: In function 'int main()':
2014_ho_t4.cpp:38:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<link[now].size(); i++){
                ~^~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n, &m, &x);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:21:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=n; i++) scanf("%d", &h[i]);
                          ~~~~~^~~~~~~~~~~~~
2014_ho_t4.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &t);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5116 KB Output is correct
2 Correct 8 ms 5240 KB Output is correct
3 Correct 9 ms 5240 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 8 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 9 ms 5340 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 9 ms 5240 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 10 ms 5204 KB Output is correct
13 Correct 10 ms 5240 KB Output is correct
14 Correct 7 ms 5112 KB Output is correct
15 Correct 9 ms 5240 KB Output is correct
16 Correct 8 ms 5112 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 7 ms 5112 KB Output is correct
19 Correct 7 ms 5112 KB Output is correct
20 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 17540 KB Output is correct
2 Correct 407 ms 27120 KB Output is correct
3 Correct 244 ms 16000 KB Output is correct
4 Correct 525 ms 27612 KB Output is correct
5 Correct 425 ms 34264 KB Output is correct
6 Correct 16 ms 5752 KB Output is correct
7 Correct 463 ms 22512 KB Output is correct
8 Correct 489 ms 24360 KB Output is correct
9 Correct 340 ms 20984 KB Output is correct
10 Correct 271 ms 18372 KB Output is correct
11 Correct 37 ms 7112 KB Output is correct
12 Correct 247 ms 18952 KB Output is correct
13 Correct 156 ms 19300 KB Output is correct
14 Correct 401 ms 22108 KB Output is correct
15 Correct 16 ms 5752 KB Output is correct
16 Correct 437 ms 25888 KB Output is correct
17 Correct 33 ms 7160 KB Output is correct
18 Correct 33 ms 7544 KB Output is correct
19 Correct 126 ms 12536 KB Output is correct
20 Correct 43 ms 7928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5116 KB Output is correct
2 Correct 8 ms 5240 KB Output is correct
3 Correct 9 ms 5240 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 8 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 9 ms 5340 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 9 ms 5240 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 10 ms 5204 KB Output is correct
13 Correct 10 ms 5240 KB Output is correct
14 Correct 7 ms 5112 KB Output is correct
15 Correct 9 ms 5240 KB Output is correct
16 Correct 8 ms 5112 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 7 ms 5112 KB Output is correct
19 Correct 7 ms 5112 KB Output is correct
20 Correct 7 ms 5112 KB Output is correct
21 Correct 528 ms 17540 KB Output is correct
22 Correct 407 ms 27120 KB Output is correct
23 Correct 244 ms 16000 KB Output is correct
24 Correct 525 ms 27612 KB Output is correct
25 Correct 425 ms 34264 KB Output is correct
26 Correct 16 ms 5752 KB Output is correct
27 Correct 463 ms 22512 KB Output is correct
28 Correct 489 ms 24360 KB Output is correct
29 Correct 340 ms 20984 KB Output is correct
30 Correct 271 ms 18372 KB Output is correct
31 Correct 37 ms 7112 KB Output is correct
32 Correct 247 ms 18952 KB Output is correct
33 Correct 156 ms 19300 KB Output is correct
34 Correct 401 ms 22108 KB Output is correct
35 Correct 16 ms 5752 KB Output is correct
36 Correct 437 ms 25888 KB Output is correct
37 Correct 33 ms 7160 KB Output is correct
38 Correct 33 ms 7544 KB Output is correct
39 Correct 126 ms 12536 KB Output is correct
40 Correct 43 ms 7928 KB Output is correct
41 Correct 306 ms 19560 KB Output is correct
42 Correct 60 ms 9340 KB Output is correct
43 Correct 310 ms 17860 KB Output is correct
44 Correct 177 ms 13268 KB Output is correct
45 Correct 380 ms 22252 KB Output is correct
46 Correct 22 ms 6904 KB Output is correct
47 Correct 415 ms 21588 KB Output is correct
48 Correct 610 ms 25644 KB Output is correct
49 Correct 438 ms 22128 KB Output is correct
50 Correct 467 ms 23268 KB Output is correct
51 Correct 63 ms 8568 KB Output is correct
52 Correct 391 ms 23856 KB Output is correct
53 Correct 501 ms 22916 KB Output is correct
54 Correct 478 ms 21496 KB Output is correct
55 Correct 388 ms 21724 KB Output is correct
56 Correct 587 ms 25684 KB Output is correct
57 Correct 116 ms 10616 KB Output is correct
58 Correct 13 ms 5496 KB Output is correct
59 Correct 399 ms 22188 KB Output is correct
60 Correct 83 ms 10232 KB Output is correct