Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
1168. Optimize Water Distribution in a Village
Bookmark
Kruskal
Prim
Input
Standard
4 Houses
Balanced
Custom
n
=
3
,
wells
=
[1,2,2]
,
pipes
=
[[1,2,1],[2,3,1]]
Graph
Well
H1
H2
H3
Sorted Edges
(empty)
Houses Connected: 0/3 | Total Cost: 0
Legend:
Standard
Current
In MST
Well Edge
Graph
Well
H1
H2
H3
Sorted Edges
(empty)
Houses Connected: 0/3 | Total Cost: 0
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H1
Well
1
H2
H1
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 0/3 | Total Cost: 0
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H1
Well
1
H2
H1
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 0/3 | Total Cost: 0
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H2
H1
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 0/3 | Total Cost: 0
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H2
H1
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 1/3 | Total Cost: 1
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 1/3 | Total Cost: 1
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
1
H3
H2
2
H2
Well
2
H3
Well
Houses Connected: 2/3 | Total Cost: 2
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
2
H2
Well
2
H3
Well
Houses Connected: 2/3 | Total Cost: 2
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
2
H2
Well
2
H3
Well
Houses Connected: 3/3 | Total Cost: 3
Legend:
Standard
Current
In MST
Well Edge
Graph
1
2
2
1
1
Well
H1
H2
H3
Sorted Edges
Cost
Node
From
2
H2
Well
2
H3
Well
Houses Connected: 3/3 | Total Cost: 3
Legend:
Standard
Current
In MST
Well Edge
algo
master
.
io
Step:
Optimize water distribution for 3 houses. Introduce a virtual "Well" node (0) and find the MST using Kruskal's algorithm.
0 / 14
Input
Standard
4 Houses
Balanced
Custom
n
=
3
,
wells
=
[1,2,2]
,
pipes
=
[[1,2,1],[2,3,1]]
0 / 14
algo
master
.
io
Step:
Optimize water distribution for 3 houses. Introduce a virtual "Well" node (0) and find the MST using Kruskal's algorithm.