Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <map>
- #include <cstring>
- #include <algorithm>
- #include <stack>
- #include <queue>
- using namespace std;
- typedef long long ll;
- const int maxn = 2e5 + 10;
- vector<pair<int, int> > graph[maxn];
- struct node {
- int idx;
- ll cost;
- node() {}
- node(int _idx, ll _cost) {
- idx = _idx;
- cost = _cost;
- }
- bool operator < (const node & tmp) const {
- return cost > tmp.cost;
- }
- };
- int main() {
- ios_base::sync_with_stdio(false);
- int n, m, k;
- cin >> n >> m >> k;
- for(int i = 0; i < m; i++) {
- int a, b, c;
- cin >> a >> b >> c;
- a--; b--;
- graph[a].push_back(make_pair(b, c));
- }
- priority_queue<node> pq;
- pq.push(node(0, 0));
- vector<int> visited(n + 1, 0);
- int E = n - 1;
- while(!pq.empty() and visited[E] < k) {
- node c = pq.top();
- pq.pop();
- visited[c.idx]++;
- if(c.idx == E) {
- cout << c.cost << " ";
- }
- if(visited[c.idx] <= k) {
- for(int i = 0; i < (int) graph[c.idx].size(); i++) {
- int neighbour = graph[c.idx][i].first;
- ll weight = graph[c.idx][i].second;
- pq.push(node(neighbour, c.cost + weight));
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement