Skip to content

Instantly share code, notes, and snippets.

@enzerr
Last active April 17, 2023 19:03
Show Gist options
  • Save enzerr/a45ffa43f6f8a9a536e0b141820670e3 to your computer and use it in GitHub Desktop.
Save enzerr/a45ffa43f6f8a9a536e0b141820670e3 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
const int maxn = 1e5 + 5, INF = 0x3f3f3f3f3f3f3f3f;
int cnt[maxn];
vector<pii> adj[maxn];
priority_queue<pii, vector<pii>, greater<pii>> pq;
int32_t main(){
int n, m, k; cin >> n >> m >> k;
for(int i = 0; i < m; i++){
int a, b, c; cin >> a >> b >> c;
adj[a].push_back({b, c});
}
pq.push({0, 1});
while(pq.size()){
auto[d, u] = pq.top(); pq.pop();
if(cnt[u]==k) continue;
cnt[u]++;
if(u==n) cout << d << " ";
for(auto[v, w] : adj[u]){
pq.push({d+w, v});
}
}
cout << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment