Skip to content

Commit cf5fe9b

Browse files
authored
Create 1196 FlightRoutes.cpp
1 parent 208c41c commit cf5fe9b

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

cses graph/1196 FlightRoutes.cpp

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

0 commit comments

Comments
 (0)