All Tracks Data Structures Disjoint Data Structures Basics of Disjoint Data Structures Problem

Count Friends
/

Disjoint data structures, Disjoint set, Disjoint set, approved

Problem
Editorial
Analytics

There are N students and M relationships of the form u v, which means that student u and student v are friends. If two students are not friends directly but they have a mutual friend, then they too become friends. Your task is to count the number of friends of the \(i^{th}\) student where \(1 \leq i \leq N\).

Input:
The first line consists of two integers N and M denoting the number of students and the number of relationships respectively.
The next M lines consists of two integers u and v denoting that student u and student v are friends. u and v can never be equal and relationships are not repeated.

Output:
Print N space separated integers which tells us the number of friends of the \(i^{th}\) student.

Constraints:
\(1 \leq N \leq 10^5\)
\(1 \leq M \leq 10^5\)
\(1 \leq u, v \leq N\)

SAMPLE INPUT
4 3
4 3
2 4
2 3
SAMPLE OUTPUT
0 2 2 2 
Explanation

For the sample test case -
Student 1 has no friends.
Student 2 is friends with student 3 and 4.
Student 3 is friends with student 2 and 4.
Student 4 is friends with student 2 and 3.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

This Problem was Asked in

Initializing Code Editor...
Notifications
View All Notifications

?