So, in your directed graph, there is an edge from 'x' to 'y' of weight 'a' iff there is an edge from 'y' to 'x' of weight 'a'. Call this graph 'G1'.
Convert 'G1' into an undirected graph 'G2' so that there is an edge from 'x' to 'y' of weight 'a' in G2 iff there is an edge from 'x' to 'y' of weight 'a' in G1.
The cost of a minimum spanning tree (MST) in G1 is necessarily equal to the cost of an MST in G2.
So, take G1 as input, convert it into G2 and feed it into Prim's algorithm. IT generates a MST on G1.
As for the second part of your Q, yes-- Prim's algorithm necessarily be less than or equal to the weight of that Hamiltonian path. If it weren't, i.e. if the Hamiltonian path is of less cost than the tree, the Hamiltonian path would be the MST itself since a simple path is also a tree. A contradiction.
This type of intermediate connectivity is often called semi-connectivity.
If you used this notion you would find out that your question already has a very comprehensive answer on stackoverflow: https://stackoverflow.com/questions/30642383/determine-if-a-graph-is-semi-connected-or-not
I will sketch it here simplified though.
Idea is to reduce problem by reducing digraph G to it's graph of SCC's, say G', that is always acyclic and then try to find a path that covers all nodes in G'. If there is no such path then it's not possible to get from some SCC to some other (G' is acyclic) and that means that vertices in them have no connections. Otherwise G' is semi-connected and so is G.
Input: digraph G = (V,E)
Output: true or false if it's semi-connected
init graph G'=(V',E') from SCC's of G where V' is set of SCC of G and E' are edges between them or $E'=\{(v_1',v_2') | v_1',v_2'\in V'$ and $\exists (v_1,v_2)\in E$, $v_1 \in v_1',v_2 \in v_2'$}
// G' guaranteed to be acyclic and this can be done in O(|V| + |E|), for example, using Kosaraju's algorithm
find topological ordering $T=(v_0,...,v_{|V'|})$ of G' // correct as G' is acyclic and also can be done in O(|V'| + |E'|) using modification of DFS.
if some possible pair $(v_i,v_{i+1})$ in T is not in E' ouput false, otherwise true // if not then $(v_{i+1},v_{i})$ also is not in E' and there is no connection between vertices in $v_i$ and $v_{i+1}$, takes O(|V'|)
Best Answer
The best way to go about this is to perform some sort of either depth first or breadth-first search through the graph: for example, the depth first search would look something like this in pseudocode (
y
in the code is a "neighbor" ofx
if there exists an edge fromx
toy
or fromy
tox
)If the search concludes after visiting all vertices, then the graph is weakly connected. Otherwise, all visited vertices form a weakly connected component.