Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

#Push bus lines, not edges#

Push bus lines, not edges

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 foreach (vertex v in busline) {
 if (v == target) {
 return distance;
 }
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

Typo

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 foreach (vertex v in busline) {
 if (v == target) {
 return distance;
 }
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

Push bus lines, not edges

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 foreach (vertex v in busline) {
 if (v == target) {
 return distance;
 }
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

Typo

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;
added 541 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 ifforeach (targetvertex isv in busline) {
 returnif distance;(v == target) {
 }
 foreach (vertex v in busline)return {distance;
 }
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 if (target is in busline) {
 return distance;
 }
 foreach (vertex v in busline) {
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;
while (q.notEmpty()) {
 busline, distance = q.pop();
 foreach (vertex v in busline) {
 if (v == target) {
 return distance;
 }
 if (visited_vertex[v]) {
 continue;
 }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;
added 541 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited[b]visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;

while (q.notEmpty()) {
 busline, distance = q.pop();
 if (target is in busline) {
 return distance;
 }
 foreach (vertex v in busline) {
 if (visited_vertex[v]) {
 continue;
  }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited[b]visited_busline[b]) {
 visited[b]visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited[b] = true;
 q.push(b, 1); // 1 = distance
}
while (q.notEmpty()) {
 busline, distance = q.pop();
 if (target is in busline) {
 return distance;
 }
 foreach (vertex v in busline) {
 foreach (busline b connected to v) {
 if (!visited[b]) {
 visited[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;

#Push bus lines, not edges#

I feel like your breadth first search could be improved if instead of pushing single edges onto your queue, you pushed a whole bus line. After all, the distance you are finding is the number of bus lines traversed, not the number of edges. So a pseudocode algorithm would be:

foreach (busline b connected to vertex 0) {
 visited_busline[b] = true;
 q.push(b, 1); // 1 = distance
}
visited_vertex[0] = true;

while (q.notEmpty()) {
 busline, distance = q.pop();
 if (target is in busline) {
 return distance;
 }
 foreach (vertex v in busline) {
 if (visited_vertex[v]) {
 continue;
  }
 visited_vertex[v] = true;
 foreach (busline b connected to v) {
 if (!visited_busline[b]) {
 visited_busline[b] = true;
 q.push(b, distance+1);
 }
 } 
 }
}

Then all that is left it to parse the original input so that each vertex v contains a list of bus lines that it is connected to.

#Typo#

This code didn't compile for me:

 if(e.d > mini)
 continue;

I believe that at some point, you changed mini to shortest_path. Also, in this line, I believe that you can use >= which can help a little in reducing your search depth by 1 level:

 if(e.d >= shortest_path)
 continue;
Post Undeleted by JS1
added 541 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83
Loading
Post Deleted by JS1
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /