Visio has an automation model that allows you to write code that will do what you want to do. Visio has built-in VBA (Visual Basic for Applications), so you can quickly get started fiddling with code. Whereas creating a VSTO add-in in C# or VB.NET takes a lot more effort just to get started.
As long as the connectors are properly glued to the shapes, you can trace the structure of the diagram. It's not really obvious how to do this, but I can offer a few tips off the top of my head. If nothing else, the terms that I mention below will help in searching for code samples and API references.
The boxes are called "2D" shapes in Visio and the connectors are called "1D". You can detect "1D" shapes by querying the shape.OneD property.
2D shapes have "FromConnects" objects and 1D shapes have "Connects" objects. Connects objects essentially encapsulate the glued end of the connector. With a Connects object, you can get the end of the connector that is glued (Begin or End), and what it is glued to (a particular connection point, or an entire shape).
In this way you can build a list of connections that note the from-box and the to-box, and thus you can understand the structure of the diagram.
You can find starting points by looking for boxes that have no incoming connections. In Visio parlance, that means no connectors have their connector End glued to a shape. (Connectors have Begin and End ends).
I'm sure I have samples laying around somewhere, but I'm not in a place that I can search for them at the moment. Here is some rough, untested code that might help you to get started:
Public Sub AnalyzePage
Dim pg As Visio.Page
Set pg = Visio.ActivePage
Dim shp As Visio.Shape
For Each shp in pg.Shapes
If (shp.OneD) Then
'// This is a connector:
'// We could examine shp.Connects to find out which
'// boxes it is glued to.
Else
'// This is not a connector...a box:
If (shp.FromConnects.Count > 0) Then
'// FromConnects are the other side of Connects. We can look
'// at each FromConnect object for this shape and determine if
'// the connector is incoming or outgoing from this shape, and
'// (with a bit of work) figure out the box on the other end
'// of the connector.
End If
End If
Next shp
End Sub