Submission #151420

# Submission time Handle Problem Language Result Execution time Memory
151420 2019-09-02T19:47:49 Z TadijaSebez None (JOI14_ho_t4) C++11
100 / 100
283 ms 17820 KB
#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;
}

Compilation message

2014_ho_t4.cpp: In function 'int main()':
2014_ho_t4.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i",&n,&m,&X);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:58:29: 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("%i",&h[i]);
                        ~~~~~^~~~~~~~~~~~
2014_ho_t4.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i %i",&u,&v,&w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2828 KB Output is correct
3 Correct 5 ms 2808 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 6 ms 2940 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 6 ms 2808 KB Output is correct
13 Correct 6 ms 2768 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 14344 KB Output is correct
2 Correct 192 ms 17652 KB Output is correct
3 Correct 138 ms 12104 KB Output is correct
4 Correct 228 ms 17788 KB Output is correct
5 Correct 178 ms 16576 KB Output is correct
6 Correct 10 ms 2936 KB Output is correct
7 Correct 127 ms 9976 KB Output is correct
8 Correct 216 ms 16988 KB Output is correct
9 Correct 153 ms 11384 KB Output is correct
10 Correct 95 ms 8696 KB Output is correct
11 Correct 27 ms 4344 KB Output is correct
12 Correct 124 ms 11256 KB Output is correct
13 Correct 57 ms 8668 KB Output is correct
14 Correct 133 ms 10428 KB Output is correct
15 Correct 9 ms 3192 KB Output is correct
16 Correct 171 ms 15940 KB Output is correct
17 Correct 23 ms 4344 KB Output is correct
18 Correct 25 ms 4856 KB Output is correct
19 Correct 57 ms 6136 KB Output is correct
20 Correct 27 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2828 KB Output is correct
3 Correct 5 ms 2808 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 5 ms 2680 KB Output is correct
8 Correct 6 ms 2940 KB Output is correct
9 Correct 6 ms 2808 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 6 ms 2808 KB Output is correct
13 Correct 6 ms 2768 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 197 ms 14344 KB Output is correct
22 Correct 192 ms 17652 KB Output is correct
23 Correct 138 ms 12104 KB Output is correct
24 Correct 228 ms 17788 KB Output is correct
25 Correct 178 ms 16576 KB Output is correct
26 Correct 10 ms 2936 KB Output is correct
27 Correct 127 ms 9976 KB Output is correct
28 Correct 216 ms 16988 KB Output is correct
29 Correct 153 ms 11384 KB Output is correct
30 Correct 95 ms 8696 KB Output is correct
31 Correct 27 ms 4344 KB Output is correct
32 Correct 124 ms 11256 KB Output is correct
33 Correct 57 ms 8668 KB Output is correct
34 Correct 133 ms 10428 KB Output is correct
35 Correct 9 ms 3192 KB Output is correct
36 Correct 171 ms 15940 KB Output is correct
37 Correct 23 ms 4344 KB Output is correct
38 Correct 25 ms 4856 KB Output is correct
39 Correct 57 ms 6136 KB Output is correct
40 Correct 27 ms 4856 KB Output is correct
41 Correct 125 ms 9336 KB Output is correct
42 Correct 36 ms 6008 KB Output is correct
43 Correct 107 ms 8128 KB Output is correct
44 Correct 113 ms 9844 KB Output is correct
45 Correct 211 ms 16724 KB Output is correct
46 Correct 20 ms 5368 KB Output is correct
47 Correct 283 ms 17248 KB Output is correct
48 Correct 245 ms 17396 KB Output is correct
49 Correct 197 ms 15384 KB Output is correct
50 Correct 252 ms 17512 KB Output is correct
51 Correct 37 ms 5372 KB Output is correct
52 Correct 209 ms 14468 KB Output is correct
53 Correct 130 ms 10460 KB Output is correct
54 Correct 170 ms 11256 KB Output is correct
55 Correct 146 ms 10232 KB Output is correct
56 Correct 254 ms 17820 KB Output is correct
57 Correct 55 ms 7544 KB Output is correct
58 Correct 8 ms 3064 KB Output is correct
59 Correct 132 ms 9976 KB Output is correct
60 Correct 63 ms 7388 KB Output is correct