An algorithm of pre-equilibrium clustering of spectator matter based on the construction of the minimum spanning tree (MST) is presented. The algorithm was implemented in the Abrasion-Ablation Monte Carlo for Colliders (AAMCC) model designed to study the characteristics of spectator matter in collisions of relativistic nuclei. Due to accounting for the pre-equilibrium clusters in modelling 208Pb–208Pb collisions at the LHC, the agreement of simulation results with experimental data on the average multiplicities of spectator nucleons was improved. The results of the AAMCC-MST were compared with experimental data on the interactions of 197Au nuclei in nuclear photoemulsion. Comparison of the yields of spectator nuclei calculated for 16O–16O collisions with the yields measured in interactions of 16O with light nuclei of photoemulsion made it possible to estimate the effect of MST-clustering in small nuclear systems.