-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1196 FlightRoutes.cpp
62 lines (51 loc) · 1.19 KB
/
1196 FlightRoutes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// JAI BAJARANG BALI
// manitianajay45
// give me some sunshine, give me some rain, give me another chance to grow up once again....
// sab moh maya hai....
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m, k;
vector<pair<ll, ll>> graph[100005];
vector<ll> shortest(100005, -1);
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for (ll i = 0; i < m; i++)
{
ll u, v, c;
cin >> u >> v >> c;
graph[u].push_back({v, c});
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
pq.push({0, 1});
vector<ll> ans;
vector<ll> cnt(n+1,0);
while (!pq.empty())
{
pair<ll, ll> p = pq.top();
pq.pop();
cnt[p.second]++;
if (p.second == n)
{
ans.push_back(p.first);
}
if(cnt[n]==k){
// cout<<"YES"<<endl;
break;
}
if(cnt[p.second]<=k){
for (auto i : graph[p.second])
{
pq.push({i.second + p.first, i.first});
}
}
}
for(auto i:ans){
cout<<i<<" ";
}
cout << endl;
return 0;
}