Friend Circles
July 29, 2020Soru: Bir grup insan birbiri ile arkadaş oluyor, Arkadaşlıklar geçişken olduğuna göre verilen input sonucu kaç tane farklı arkadaşlık networku oluşur. Geçişkenliğin tanımını yapalım A ile B, B ile C arkadaş ise A ile C arkadaştır.
Çözüm
Klasik bir disjoint set problemi. Her bir arkadaşlık ekleme(merge) işlemi yaparken iki kişi aynı networkte değilse network sayısı bir azalır.
Çözüm alternatifi olarak her bir insan için dfs-visit çalıştırıp her bir connected component için network sayısını her seferinde bir artırabilirsiniz.
|
|
Görselleştirmesini graphviz kullarak yapalım.
Graphviz çizimini nasıl yaptığıma dair kodu buraya bırakıyorum.
|
|
hidden
The Review Is the Action Item
2024/05/30The Review Is the Action ItemI like to consider running an incident review to be its own action item. Other follow-ups emerging from it are a plus, but the point is to learn from incidents, and the review gives room for that to happen.This is no…
via Ferd.caFinding a New Software Developer Job
For the first time ever, I was laid off, and had to find a new software developer job. I managed to find a new one, but it took longer than I thought, and it was a lot of work. I … Continue reading →
via Henrik Warne's blogHOWTO: Change your behavior
In theory, behavior change should be easy. At first glance, it seems like you control your behavior. So, if you desire different behavior, why doesn’t your behavior change as instantly as your desire to change it? In short, lasting change of habitual behavio…
via Matt Might's blog