Recovering static and time-varying communities using persistent edges