[2407.04260] Efficient Detection of Long Consistent Cycles and its Application to Distributed Synchronization