I think the detail is that
first, the game has several linking lines which match the number of unit groups(because its upperbound is limited);
second, if the linking line is not empty, the group definity will clear off the linking line belong to the group;
finally, add the addresses of the units to the group corresponding to the linking line.