Dijkstra & Bellman-Ford Shortest Path Visualizer
Paste weighted edge lists from Codeforces or CSES, toggle directed/undirected edges with one key (D), and inspect every priority-queue pop, edge relaxation, and distance update step-by-step.
Algorithm Comparison
| Algorithm | Time Complexity | Negative Weights | Best Contest Use Case |
|---|---|---|---|
| Dijkstra (Priority Queue) | O((V + E) log V) |
No | Non-negative weighted directed or undirected graphs (e.g. CSES Shortest Routes I) |
| Bellman-Ford | O(V * E) |
Yes + Cycle Check | Graphs with negative edges or cycle detection (e.g. CSES High Score / Cycle Finding) |
| BFS (Unweighted) | O(V + E) |
Uniform weight 1 | Shortest path by edge count in unweighted graphs (BFS Guide) |
Pasteable Weighted Graph Example
Copy these u v w lines straight into the Edges List panel (or click Load Dijkstra Demo above):
# Directed weighted graph (u v w) 1 2 4 1 3 2 3 2 1 2 4 5 3 4 8 3 5 10 4 6 2 5 6 3
Debugging Checklist for Contests
Multi-Edges Between Same Vertices
CP Graph Editor automatically curves parallel multi-edges and isolates their weight badges so you never miss a shorter parallel edge overriding an earlier test edge.1-Indexed vs 0-Indexed Mismatch
Use the header1-based / 0-based switch before running Dijkstra when mixing LeetCode (0-indexed) and Codeforces/CSES (1-indexed) constraints.
Stale Queue Entries in Priority Queue
Watch how Dijkstra skips outdated queue states once a node has already settled with a smaller shortest distancedist[u].
Frequently Asked Questions
How do I visualize weighted edges in Dijkstra?
Enable Weighted (W) mode, paste u v w lines into Edges List, open the Algorithms tab, choose Dijkstra Shortest Path, and click Launch Algorithm Tracer.
Can edges contain custom labels or negative weights?
Yes. Negative numbers work cleanly with Bellman-Ford negative-cycle tracing, and string labels like "fast" render cleanly beside numeric edges.