#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e5 + 5;
const int inf = 1e18;
int dist[N],n,m;
vector<int>g[N];
priority_queue<int>cost[N];
void dijkstra(int s) {
priority_queue<pii,vector<pii>,greater<pii>>q;
for (int i = 1; i <= n; i++) dist[i] = inf;
q.push({0,s});
dist[s] = 0;
while (!q.empty()) {
int u = q.top().se,c = q.top().fi;
q.pop();
if (dist[u] != c) continue;
//minimum path match with maximum cost
for (int i = 0; i < (int)g[u].size(); i++) {
int v = g[u][i];
int c = cost[v].top(); cost[v].pop();
if (dist[v] > dist[u] + c) {
dist[v] = dist[u] + c;
q.push({dist[v],v});
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u,v,c;
cin >> u >> v >> c;
g[v].push_back(u);
cost[u].push(c);
}
dijkstra(n);
cout << dist[1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5712 KB |
Output is correct |
2 |
Correct |
5 ms |
5968 KB |
Output is correct |
3 |
Correct |
11 ms |
7360 KB |
Output is correct |
4 |
Correct |
85 ms |
19560 KB |
Output is correct |
5 |
Correct |
95 ms |
19708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5712 KB |
Output is correct |
2 |
Correct |
5 ms |
5968 KB |
Output is correct |
3 |
Correct |
11 ms |
7400 KB |
Output is correct |
4 |
Correct |
54 ms |
12816 KB |
Output is correct |
5 |
Correct |
78 ms |
15304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
6992 KB |
Output is correct |
2 |
Correct |
16 ms |
7248 KB |
Output is correct |
3 |
Correct |
151 ms |
21320 KB |
Output is correct |
4 |
Correct |
185 ms |
21724 KB |
Output is correct |
5 |
Correct |
182 ms |
20924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
16456 KB |
Output is correct |
2 |
Correct |
157 ms |
21320 KB |
Output is correct |
3 |
Correct |
194 ms |
22396 KB |
Output is correct |
4 |
Correct |
207 ms |
22408 KB |
Output is correct |
5 |
Correct |
134 ms |
22464 KB |
Output is correct |