flowchart TD
A[Initialize dist array] --> B[Repeat V 1 rounds]
B --> C[Scan every edge u v]
C --> D{dist u w dist v}
D -- Yes --> E[Relax dist v]
D -- No --> F[Keep current]
E --> G{More edges}
F --> G
G -- Yes --> C
G -- No --> H[One extra scan]
H --> I{Still relaxes}
I -- Yes --> J[Negative cycle]
I -- No --> K[Return distances]
sequenceDiagram
participant Lp as V1Loop
participant E as EdgeList
participant D as DistTable
Lp->>E: iterate edges
E->>D: try relax u v w
D-->>Lp: changed or not
Lp->>E: final cycle check