# Untitled

unknown
plain_text
a year ago
2.7 kB
4
Indexable
Never
```#include <bits/stdc++.h>
using namespace std;

int pandemic(int n, vector<vector<int>>&bus, int src, int des, int k,int m){
++k;
for(int i=0; i<m; ++i)
{
}

vector<vector<int>> cost(n, vector<int>(k+1, INT_MAX));
cost[src][0] = 0;

priority_queue<pair<int,int>> q;
q.push({src, 0});

while(!q.empty())
{
int node = q.top().first, stops = q.top().second;
q.pop();

{
int nbr = e[0], ecost = e[1];
if(stops + 1 <= k and cost[nbr][stops+1] > cost[node][stops] + ecost)
{
cost[nbr][stops+1] = cost[node][stops] + ecost;
q.push({nbr, stops+1});
}
}
}

int ans = INT_MAX;
for(int i=1; i<=k; ++i)
ans = min(ans, cost[des][i]);

return ans == INT_MAX ? -1 : ans;
}

int main(){
int n;
cin>>n;
int m;
cin>>m;
vector<vector<int>>bus(m);
for(int i=0;i<m;i++)
{
int from,to,price;
cin>>from>>to>>price;
bus[i].push_back(from);
bus[i].push_back(to);
bus[i].push_back(price);
}
int src,dest,k;
cin>>src>>dest>>k;
cout<<pandemic(n,bus, src, dest, k,m);

}

/*
Crio Methodology

Milestone 1: Understand the problem clearly
1. Ask questions & clarify the problem statement clearly.
2. Take an example or two to confirm your understanding of the input/output & extend it to test cases
Milestone 2: Finalize approach & execution plan
1. Understand what type of problem you are solving.
a. Obvious logic, tests ability to convert logic to code
b. Figuring out logic
c. Knowledge of specific domain or concepts
d. Knowledge of specific algorithm
e. Mapping real world into abstract concepts/data structures
2. Brainstorm multiple ways to solve the problem and pick one
3. Get to a point where you can explain your approach to a 10 year old
4. Take a stab at the high-level logic & write it down.
5. Try to offload processing to functions & keeping your main code small.
Milestone 3: Code by expanding your pseudocode
1. Make sure you name the variables, functions clearly.
2. Avoid constants in your code unless necessary; go for generic functions, you can use examples for your thinking though.
3. Use libraries as much as possible
Milestone 4: Prove to the interviewer that your code works with unit tests
1. Make sure you check boundary conditions
2. Time & storage complexity
3. Suggest optimizations if applicable
*/```