# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
517219 |
2022-01-22T18:08:47 Z |
azberjibiou |
None (JOI14_ho_t4) |
C++17 |
|
182 ms |
25608 KB |
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<double, double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pmax pair<__int128, __int128>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=100020;
const int mxM=2500000;
const int mxK=105;
const int MOD=1000000007;
const ll INF=1000000000000000001;
int N, M;
ll X;
ll H[mxN];
vector <pll> v[mxN];
ll dis[2*mxN];
bool Chk[2*mxN];
priority_queue <pll> pq;
ll ans;
int main()
{
gibon
cin >> N >> M >> X;
for(int i=1;i<=N;i++) cin >> H[i];
for(int i=0;i<M;i++)
{
int a, b, t;
cin >> a >> b >> t;
if(H[a]>=t) v[a].emplace_back(b, t);
if(H[b]>=t) v[b].emplace_back(a, t);
}
for(int i=1;i<=2*N;i++) dis[i]=INF;
dis[1]=0;
pq.push({0, 1});
while(!pq.empty())
{
int now=pq.top().sec;
pq.pop();
if(Chk[now]) continue;
Chk[now]=true;
if(now<=N)
{
if(dis[N+now]>X)
{
dis[N+now]=X;
pq.push({-X, N+now});
}
for(pll nxt : v[now])
{
if(X>dis[now]+nxt.sec)
{
if(dis[nxt.fir]>max(dis[now]+nxt.sec, X-H[nxt.fir]))
{
dis[nxt.fir]=max(dis[now]+nxt.sec, X-H[nxt.fir]);
pq.push({-dis[nxt.fir], nxt.fir});
}
}
else if(dis[nxt.fir+N]>2*nxt.sec-X+2*dis[now])
{
dis[nxt.fir+N]=2*nxt.sec-X+2*dis[now];
pq.push({-dis[nxt.fir+N], nxt.fir+N});
}
}
}
else
{
for(pll nxt : v[now-N])
{
if(dis[N+nxt.fir]>dis[now]+2*nxt.sec)
{
dis[N+nxt.fir]=dis[now]+2*nxt.sec;
pq.push({-dis[N+nxt.fir], N+nxt.fir});
}
}
}
}
ans=min(dis[2*N]+H[N], 2*dis[N]+H[N]-X);
cout << (ans>=INF ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2768 KB |
Output is correct |
3 |
Correct |
3 ms |
2768 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2760 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2768 KB |
Output is correct |
9 |
Correct |
3 ms |
2840 KB |
Output is correct |
10 |
Correct |
3 ms |
2740 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
3 ms |
2768 KB |
Output is correct |
13 |
Correct |
3 ms |
2824 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
9348 KB |
Output is correct |
2 |
Correct |
129 ms |
25608 KB |
Output is correct |
3 |
Correct |
97 ms |
14660 KB |
Output is correct |
4 |
Correct |
146 ms |
24036 KB |
Output is correct |
5 |
Correct |
126 ms |
24392 KB |
Output is correct |
6 |
Correct |
6 ms |
2972 KB |
Output is correct |
7 |
Correct |
70 ms |
10344 KB |
Output is correct |
8 |
Correct |
177 ms |
21856 KB |
Output is correct |
9 |
Correct |
92 ms |
12140 KB |
Output is correct |
10 |
Correct |
55 ms |
9032 KB |
Output is correct |
11 |
Correct |
19 ms |
4800 KB |
Output is correct |
12 |
Correct |
82 ms |
14716 KB |
Output is correct |
13 |
Correct |
36 ms |
12856 KB |
Output is correct |
14 |
Correct |
89 ms |
11256 KB |
Output is correct |
15 |
Correct |
5 ms |
3280 KB |
Output is correct |
16 |
Correct |
109 ms |
23756 KB |
Output is correct |
17 |
Correct |
12 ms |
4740 KB |
Output is correct |
18 |
Correct |
14 ms |
5376 KB |
Output is correct |
19 |
Correct |
33 ms |
6184 KB |
Output is correct |
20 |
Correct |
18 ms |
5492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2768 KB |
Output is correct |
3 |
Correct |
3 ms |
2768 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2760 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2768 KB |
Output is correct |
9 |
Correct |
3 ms |
2840 KB |
Output is correct |
10 |
Correct |
3 ms |
2740 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
3 ms |
2768 KB |
Output is correct |
13 |
Correct |
3 ms |
2824 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
123 ms |
9348 KB |
Output is correct |
22 |
Correct |
129 ms |
25608 KB |
Output is correct |
23 |
Correct |
97 ms |
14660 KB |
Output is correct |
24 |
Correct |
146 ms |
24036 KB |
Output is correct |
25 |
Correct |
126 ms |
24392 KB |
Output is correct |
26 |
Correct |
6 ms |
2972 KB |
Output is correct |
27 |
Correct |
70 ms |
10344 KB |
Output is correct |
28 |
Correct |
177 ms |
21856 KB |
Output is correct |
29 |
Correct |
92 ms |
12140 KB |
Output is correct |
30 |
Correct |
55 ms |
9032 KB |
Output is correct |
31 |
Correct |
19 ms |
4800 KB |
Output is correct |
32 |
Correct |
82 ms |
14716 KB |
Output is correct |
33 |
Correct |
36 ms |
12856 KB |
Output is correct |
34 |
Correct |
89 ms |
11256 KB |
Output is correct |
35 |
Correct |
5 ms |
3280 KB |
Output is correct |
36 |
Correct |
109 ms |
23756 KB |
Output is correct |
37 |
Correct |
12 ms |
4740 KB |
Output is correct |
38 |
Correct |
14 ms |
5376 KB |
Output is correct |
39 |
Correct |
33 ms |
6184 KB |
Output is correct |
40 |
Correct |
18 ms |
5492 KB |
Output is correct |
41 |
Correct |
81 ms |
9512 KB |
Output is correct |
42 |
Correct |
20 ms |
6724 KB |
Output is correct |
43 |
Correct |
65 ms |
8416 KB |
Output is correct |
44 |
Correct |
72 ms |
12224 KB |
Output is correct |
45 |
Correct |
151 ms |
23252 KB |
Output is correct |
46 |
Correct |
11 ms |
5744 KB |
Output is correct |
47 |
Correct |
182 ms |
22880 KB |
Output is correct |
48 |
Correct |
178 ms |
23024 KB |
Output is correct |
49 |
Correct |
141 ms |
19400 KB |
Output is correct |
50 |
Correct |
149 ms |
24624 KB |
Output is correct |
51 |
Correct |
20 ms |
6084 KB |
Output is correct |
52 |
Correct |
127 ms |
17764 KB |
Output is correct |
53 |
Correct |
79 ms |
10824 KB |
Output is correct |
54 |
Correct |
89 ms |
12396 KB |
Output is correct |
55 |
Correct |
86 ms |
11340 KB |
Output is correct |
56 |
Correct |
181 ms |
23624 KB |
Output is correct |
57 |
Correct |
34 ms |
8804 KB |
Output is correct |
58 |
Correct |
4 ms |
3144 KB |
Output is correct |
59 |
Correct |
75 ms |
10212 KB |
Output is correct |
60 |
Correct |
34 ms |
8676 KB |
Output is correct |