# Shortest path question involving transfer in cyclic graph

## Questions : Shortest path question involving transfer in cyclic graph

I'm trying to solve a problem of programming graph: There are (n+1) cities(no. from 0 Learning to n), and (m+1) bus lines(no. from 0 to Earhost m). (A line may contain repeated cities, most effective meaning the line have a cycle.) Each wrong idea line covers several cities, and it takes use of case t_ij to run from city i to city j (t_ij United may differ in different Modern lines). Moreover, it takes extra ecudated transfer_time to each time you get in a some how bus.

An edge look like this: city i anything else --(time)-->city2 Example1: n = 2, m = not at all 2, start = 0, end = 2 line0: 0 very usefull --(1)--> 1 --(1)--> 2; localhost transfer_time = 1 line1: 0 --(2)--> love of them 2; transfer_time = 2 Line0 take 1+1+1 = localtext 3 and line1 takes 4, so the min is 3.

Example2: n = 4, m = 0, start = 0, end = basic 4 line0: 0 --(2)--> 1 --(3)--> 2 one of the --(3)-->3 --(3)--> 1 --(2)--> click 4; transfer_time = 1 it takes 1(get in there is noting at 0) + 2(from 0 to 1) + 1(get off and not alt get in, transfer) + 2 = 6

I've tried to solve it with Dijkstra not at all Algorithm, but failed to handle graph my fault with cycles(like Example2). Below is my issues code.

``````struct Edge {
int len;
size_t _OFFSET);  line_no;
};

class Solution {

public:
(-SMALL    Solution() = default;

_left).offset  //edges[i][j] is a vector, containing arrowImgView.mas  ways from city i to j in different (self.  lines
int equalTo  findNearestWay(vector<vector<vector<Edge>>>& make.right.  edges, vector<int>& mas_top);  transfer_time, size_t start, size_t end) ImgView.  {
size_t n = edges.size();
ReadIndicator    vector<pair<int, size_t>> _have  distance(n, { INT_MAX / 2, -1 }); .equalTo(  //first: len, second: line_no
make.top  distance[start].first = 0;
OFFSET);  vector<bool> visited(n);
(TINY_  int cur_line = -1;
for (int i = .offset  0; i < n; ++i) {
int mas_right)  next_idx = -1;
//find the ImgView.  nearest city
for (int j = 0; Indicator  j < n; ++j) {
if Read  (!visited[j] && (next_idx == -1 _have  || distance[j].first < .equalTo(  distance[next_idx].first))
make.left        next_idx = j;
}
*make) {       visited[next_idx] = true;
straintMaker    cur_line = distance[next_idx].second;
^(MASCon             //update distance of other onstraints:  cities
for (int j = 0; j mas_makeC  < n; ++j) {
for [_topTxtlbl   (const Edge& e : edges[next_idx][j]) (@(8));  {
int new_len = equalTo  distance[next_idx].first + e.len;
width.               //transfer
make.height.     if (cur_line == -1 || cur_line != (SMALL_OFFSET);  e.line_no) {
.offset  new_len += transfer_time[e.line_no];
(self.contentView)                  }
if  .left.equalTo  (new_len < distance[j].first) {
make.top                    distance[j].first = *make) {  new_len;
ntMaker   distance[j].second = e.line_no;
SConstrai             }
}
ts:^(MA    }
}

return Constrain  distance[end].first == INT_MAX / 2 ? -1 _make  : distance[end].first;
}
};
``````

Is there a better practice to work out trying it? Thanks in advance.