Area 3.2 : Prim
Example :
Figure 8.1 : Prim
Prim is the same type as Kruskal.
For the algorithm, we need two arrays, dis[] and vis[].
Step 1, start from a node(Here is 1).
Then set dis[1]=0, vis[1]=1.Update other points by its edges.
array dis[]
0 | inf | 3.27 | inf | inf | 4.67 | inf |
array vis[]
1 | 0 | 0 | 0 | 0 | 0 | 0 |
Table 8.1-a : Prim(a)
Then, find the mininum edge (1({vis[i]=1}, v) that vis[v]=0(Here is 3), do as that.
array dis[]
0 | inf | 3.27 | 4.39 | inf | 4.38 | inf |
array vis[]
1 | 0 | 1 | 0 | 0 | 0 | 0 |
Table 8.1-b : Prim(b)
Wait… It seems like Dijkstra.
So, it can be optimized by heap(priority_queue).
If you know that, you can complete the problem with less time.
This is Prim.
Given Score :
Difficulty : 2
x Basic Score : 44
Score : 838
All Figures in the passage :
http://59.60.22.18:2500/wordpress/wp-content/uploads/2024/01/C03_Figures.zip