P18174 [GeeksforGeeks] Villain con0511
普及
题目描述

The minions are very elitist in nature. If minion x admires minion y, then y thinks too highly of himself and does not admire x back. Also, if x admires y, x also admires everyone that y admires.
All the minions are going to be present at the Villain Con. They want to make sure that they do not dress in the same color as someone who admires them.
There are N minions and M relations between them. The relations are given in a 2D array mat. Each relation is given in x_{i} , y_{i} format where y_{i} admires x_{i. }Find the minimum number of different colours that the minions will be dressing in.

Example 1:
Input:
N = 5, M = 6
mat = {{1, 3},
{2, 3},
{3, 4},
{1, 4},
{2, 5},
{3, 5}}
Output: 3
Explaination:
If we assign red colour to 1 and 2,
green colour to 3, and blue colour to 4 and 5, then
every minion will have different coloured dresses
from the one who admires them.
Example 2:
Input:
N = 3, M = 2
mat = {{1,3},{2,3}}
Output:
2
Explanation:
If we assign red colour to 1 and 2, and green colour to 3, then the condition is satisfied.
Your Task:
You do not need to read input or print anything. Your task is to complete the function minColour() which takes N, M and mat[][] as input parameters and returns the minimum number of colours required.

Expected Time Complexity: O(N+M)
Expected Auxiliary Space: O(N+M)

Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ M ≤ 2*10^{5}
1 ≤ x_{i} , y_{i} ≤ N

输入格式

见题面

输出格式

见题面

样例输入
N = 5, M = 6 mat = {{1, 3}, {2, 3}, {3, 4}, {1, 4}, {2, 5}, {3, 5}}
样例输出
3