///EVERYONE BELIEVE IN GODTAEGYU
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, i, j, k;
int x, h[100141];
vector<pair<int,int>>graph[100141];
unordered_map<long long, int>dist;
priority_queue<pair<int,pair<int,int>>>pq;
inline pair<int,int> lltop(long long x)
{
return {x/MOD, x%MOD};
}
inline long long ptoll(pair<int,int> x)
{
return x.first * MOD + x.second;
}
void f(int tree, int godo, int thist)
{
if(dist.find(ptoll({tree, godo})) == dist.end())
{
dist[ptoll({tree, godo})] = thist;
pq.push({thist, {tree, godo}});
}
else if(dist[ptoll({tree, godo})] > thist)
{
dist[ptoll({tree, godo})] = thist;
pq.push({thist, {tree, godo}});
}
}
int main(){
iostream::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(cin>>n>>m>>x; i<n;)
{
cin>>h[++i];
}
for(;m--;)
{
cin>>i>>j>>k;
if(h[i] >= k)
graph[i].push_back({j, k});
if(h[j] >= k)
graph[j].push_back({i, k});
}
dist[ptoll({1, x})] = 0;
pq.push({0,{1,x}});
while(!pq.empty())
{
x = pq.top().first;
tie(m, i) = pq.top().second;
pq.pop();
if(dist[ptoll({m, i})] != x)
continue;
for(auto next : graph[m])
{ //m = 현재 나무, i = 현재 높이, j = 다음 나무, k = 다음 나무 거리
tie(j, k) = next;
if(i < k){
if(h[m] >= k)
f(j, 0, x + k - i + k);
}
else if(i - k > h[j]) f(j, h[j], x + i - h[j]);
else f(j, i - k, x + k);
}
if(m == n)
f(n, h[n], x + h[n] - i);
}
if(dist.find(ptoll({n, h[n]})) == dist.end())
cout<<-1;
else cout<<dist[ptoll({n,h[n]})];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
50 ms |
2808 KB |
Output is correct |
3 |
Correct |
43 ms |
2936 KB |
Output is correct |
4 |
Correct |
9 ms |
2808 KB |
Output is correct |
5 |
Correct |
20 ms |
2808 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
51 ms |
2808 KB |
Output is correct |
9 |
Correct |
28 ms |
2808 KB |
Output is correct |
10 |
Correct |
38 ms |
2908 KB |
Output is correct |
11 |
Correct |
3 ms |
2680 KB |
Output is correct |
12 |
Correct |
56 ms |
2808 KB |
Output is correct |
13 |
Correct |
51 ms |
2808 KB |
Output is correct |
14 |
Correct |
13 ms |
2680 KB |
Output is correct |
15 |
Correct |
52 ms |
2808 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
5 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
2808 KB |
Output is correct |
20 |
Correct |
5 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
954 ms |
8836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
50 ms |
2808 KB |
Output is correct |
3 |
Correct |
43 ms |
2936 KB |
Output is correct |
4 |
Correct |
9 ms |
2808 KB |
Output is correct |
5 |
Correct |
20 ms |
2808 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
51 ms |
2808 KB |
Output is correct |
9 |
Correct |
28 ms |
2808 KB |
Output is correct |
10 |
Correct |
38 ms |
2908 KB |
Output is correct |
11 |
Correct |
3 ms |
2680 KB |
Output is correct |
12 |
Correct |
56 ms |
2808 KB |
Output is correct |
13 |
Correct |
51 ms |
2808 KB |
Output is correct |
14 |
Correct |
13 ms |
2680 KB |
Output is correct |
15 |
Correct |
52 ms |
2808 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
5 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
2808 KB |
Output is correct |
20 |
Correct |
5 ms |
2812 KB |
Output is correct |
21 |
Incorrect |
954 ms |
8836 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |