# -*- coding : utf-8 -*-
"""
@author: 2023数据赋能俱乐部
@Description: 迪杰斯特拉算法
@Date: 2024-4-4 15:36
"""
import random
from heapq import heappop, heappush
from math import inf
from typing import List
# 本代码可以直接提交力扣2642测评
# https://leetcode.cn/problems/design-graph-with-shortest-path-calculator
class Graph:
def __init__(self, n: int, edges: List[List[int]]): # edges为有向边三元组(x, y, 权重)
a = [[] for _ in range(n)]
self.a = a; self.n = n
# 邻接表
for x, y, w in edges:
a[x].append((w, y))
# 邻接矩阵
self.g = [[inf] * n for _ in range(n)]
for x, y, w in edges:
self.g[x][y] = w # 添加一条边
def addEdge(self, e: List[int]) -> None:
x, y, w = e
# 邻接表
self.a[x].append((w, y))
# 邻接矩阵
self