LOKBIL - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

Most of the people helped our cook to find the most popular friend and he is very happy now. Facebook walls didn’t get spammed. But some of you got stuck in finding him, and thus, our cook wants to explain how to find " the most popular friend". It’s quite simple, create a matrix of friends such that if ‘i’ is a friend of ‘j’ then friend[i][j] =1, else friend[i][j]=0. Now, run Breadth First Search on each friend to find the distances of each friend from him. After finding this, calculate the average distance of everyone from him. After calculating it for all, print the friend with the smallest average. Yes, he is the one.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

1 Like

Why TLE?? CodeChef: Practical coding for everyone

Hey @bhaveshsp, it would be really helpful if you can briefly explain the logic that you have implemented in your code as it will help us understand what is actually happening and where you might have gone wrong.

Its the same approach that has been explained in the editorial
For each friend calculate the average distance from every other friend using DFS
Output The Friend with the Min Average Distance