classSolution{public:intnetworkDelayTime(vector<vector<int>>& times,int n,int k){constint inf = INT_MAX /2;
vector<vector<int>>g(n,vector<int>(n, inf));for(auto&t : times){int x = t[0]-1, y = t[1]-1;
g[x][y]= t[2];}
vector<int>dist(n, inf);
dist[k -1]=0;
vector<int>used(n);for(int i =0; i < n;++i){int x =-1;for(int y =0; y < n;++y){if(!used[y]&&(x ==-1|| dist[y]< dist[x])){
x = y;}}
used[x]=true;for(int y =0; y < n;++y){
dist[y]=min(dist[y], dist[x]+ g[x][y]);}}int ans =*max_element(dist.begin(), dist.end());return ans == inf ?-1: ans;}};
classSolution{private:staticconstexprint INF =10000*101+1;public:intfindCheapestPrice(int n, vector<vector<int>>& flights,int src,int dst,int k){
vector<vector<int>>f(k +2,vector<int>(n, INF));
f[0][src]=0;for(int t =1; t <= k +1;++t){for(auto&& flight: flights){int j = flight[0], i = flight[1], cost = flight[2];
f[t][i]=min(f[t][i], f[t -1][j]+ cost);}}int ans = INF;for(int t =1; t <= k +1;++t){
ans =min(ans, f[t][dst]);}return(ans == INF ?-1: ans);}};
classSolution{staticconstexprint dirs[4][2]={{1,0},{-1,0},{0,1},{0,-1}};public:intminimumObstacles(vector<vector<int>>&grid){int m = grid.size(), n = grid[0].size();int dis[m][n];memset(dis,0x3f,sizeof(dis));
dis[0][0]=0;
deque<pair<int,int>> q;
q.emplace_front(0,0);while(!q.empty()){auto[x, y]= q.front();
q.pop_front();for(auto&[dx, dy]: dirs){int nx = x + dx, ny = y + dy;if(0<= nx && nx < m &&0<= ny && ny < n){int g = grid[nx][ny];if(dis[x][y]+ g < dis[nx][ny]){
dis[nx][ny]= dis[x][y]+ g;
g ==0? q.emplace_front(nx, ny): q.emplace_back(nx, ny);}}}}return dis[m -1][n -1];}};