[Python3] Prim's algo
Prim\'s algo \nPer Wikipedia, Prim\'s (also known as Jarn\xEDk\'s) algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected 
Prim\'s algo \nPer [Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm), Prim\'s (also known as Jarn\xEDk\'s) algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex. \n\nMy implementation reflects below coursera course by Prof. Robert Sedgewick\nhttps://www.coursera.org/lecture/algorithms-part2/prims-algorithm-HoHKu\n\n```\nclass Solution:\n    def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        graph = dict()\n        for u, v, w in edges: \n            graph.setdefault(u, []).append((v, w))\n            graph.setdefault(v, []).append((u, w))\n            \n        ref = self.mst(n, graph)\n        critical, pseudo = [], []\n        for i in range(len(edges)):\n            if self.mst(n, graph, exclude=edges[i][:2]) > ref: critical.append(i)\n            elif self.mst(n, graph, init=edges[i]) == ref: pseudo.append(i)\n        return [critical, pseudo]\n            \n        \n    def mst(self, n, graph, init=None, exclude=None):\n        """Return weight of MST of given graph using Prim\'s algo"""\n\n        def visit(u): \n            """Mark node and put its edges to priority queue"""\n            marked[u] = True\n            for v, w in graph.get(u, []):\n                if exclude and u in exclude and v in exclude: continue\n                if not marked[v]: heappush(pq, (w, u, v))\n                    \n        ans = 0\n        marked = [False]*n\n        pq = [] #min prioirty queue\n        \n        if init: \n            u, v, w = init\n            ans += w\n            marked[u] = marked[v] = True\n            visit(u) or visit(v)\n        else:\n            visit(0)\n\n        while pq: \n            w, u, v = heappop(pq)\n            if marked[u] and marked[v]: continue\n            ans += w\n            if not marked[u]: visit(u)\n            if not marked[v]: visit(v)\n                \n        return ans if all(marked) else inf\n```
['Python3']