Team Formation

0

0 votes
DFS, Easy
Problem

USICT has called students from different colleges to participate in CODESTER. Many students have arrived on campus for the participation in event. To brief them about the event the students were sent to room number 0,1,2,3,4,5,6,7,8 and 9 respectively. After the briefing all the students were called to the ground, and were asked to stand in a matrix of N*N and holding a banner representing the room number they were in earlier. Teams were formed in the following manner: 1. Two member can be in a team only if they were in the same room during briefing. 2. If two members are adjacent. Let positions be given by (R,C) R=row number and C=coloumn number:

    (1,1) (1,2) (1,3)
    (2,1) (2,2) (2,3)
    (3,1) (3,2) (3,3)
    Then (1,1), (1,2), (1,3), (2,1), (2,3),(3,1),(3,2) and (3,3) are adjacent to position (2,2)

If both the conditions are fulfilled then the members are considered in the same team. However if person A & person B are in a team and person B & person C satisfy the conditions abover, then A, B & C are considered in the same team(similar to chain formation).

EXample: For 9 students standing in 3*3 matrix formation in the ground after briefing.

1 2 3

4 1 6

7 1 9

Person at position (1,1) , (2,2) and (3,2) form a team. They were in room number 1 during briefing.

Person at (1,1) and (3,2) are not adjacent but still are in same team because of the chain formation.

Once the teams formed ,all the team members leave their places and get together.

You need to tell the number of maximum members in a team from each room. If there are more than one team possible from one room, then one team is selected at random.

Input :

First line contains a single integer N.

Next N lines consists of N intgers each denoting the room number the person at that location was earlier.

Output :

Print 10 integers in separate lines denoting the number of members of the team from room 0 to 9 respectively.

Constraints :

1 <= N <= 1500

Subtask 1 :  20 points

    1 <= N <= 250

Subtask 2 : 80 points

    1 <= N <= 1500
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Explanation :

For room number 0 the team with maximum members in it will have 3 members

For room number 1 the team with maximum members in it will have 8 members

For room number 2 the team with maximum members in it will have 3 members

For room number 3 the team with maximum members in it will have 1 members

For room number 4 the team with maximum members in it will have 1 members

For room number 5 the team with maximum members in it will have 0 members

For room number 6 the team with maximum members in it will have 1 members

For room number 7 the team with maximum members in it will have 1 members

For room number 8 the team with maximum members in it will have 2 members

For room number 9 the team with maximum members in it will have 1 members

Editor Image

?