Graph class constructor Examples: >>> graph_test = Graph(1) >>> graph_test.num_nodes 1 >>> graph_test.dist [0] >>> graph_test.par [-1] >>> graph_test.adjList {}
(self, num)
| 212 | |
| 213 | class Graph: |
| 214 | def __init__(self, num): |
| 215 | """ |
| 216 | Graph class constructor |
| 217 | |
| 218 | Examples: |
| 219 | >>> graph_test = Graph(1) |
| 220 | >>> graph_test.num_nodes |
| 221 | 1 |
| 222 | >>> graph_test.dist |
| 223 | [0] |
| 224 | >>> graph_test.par |
| 225 | [-1] |
| 226 | >>> graph_test.adjList |
| 227 | {} |
| 228 | """ |
| 229 | self.adjList = {} # To store graph: u -> (v,w) |
| 230 | self.num_nodes = num # Number of nodes in graph |
| 231 | # To store the distance from source vertex |
| 232 | self.dist = [0] * self.num_nodes |
| 233 | self.par = [-1] * self.num_nodes # To store the path |
| 234 | |
| 235 | def add_edge(self, u, v, w): |
| 236 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected