import
java.io.*;
import
java.util.*;
public
class
GFG
{
public
static
int
compare(Pair<Integer, Integer> a,
Pair<Integer, Integer> b)
{
if
(a.first == b.first) {
return
(a.second < b.second) ? -
1
:
1
;
}
else
{
return
(a.first > b.first) ? -
1
:
1
;
}
}
static
void
addEdge(List<List<Integer>> adj,
int
u,
int
v)
{
adj.get(u).set(v,
1
);
adj.get(v).set(u,
1
);
}
static
int
minimumDays(
int
V,
int
[][] Edges,
int
E)
{
List<List<Integer> > adj =
new
ArrayList<>(V);
for
(
int
i =
0
; i < V; i++) {
adj.add(
new
ArrayList<>(Collections.nCopies(V,
0
)));
}
for
(
int
i =
0
; i < E; i++) {
int
u = Edges[i][
0
];
int
v = Edges[i][
1
];
addEdge(adj, u, v);
}
List<Pair<Integer, Integer>> vdegree =
new
ArrayList<>(V);
for
(
int
i =
0
; i < V; i++) {
vdegree.add(
new
Pair<>(
0
, i));
}
for
(
int
i =
0
; i < V; i++) {
int
degree =
0
;
vdegree.get(i).second = i;
for
(
int
j =
0
; j < V; j++) {
if
(adj.get(i).get(j) !=
0
) {
degree++;
}
}
vdegree.get(i).first = degree;
}
vdegree.sort((a, b) -> compare(a, b));
int
[] vorder =
new
int
[V];
for
(
int
i =
0
; i < V; i++) {
vorder[i] = vdegree.get(i).second;
}
int
[] color =
new
int
[V];
for
(
int
i =
0
; i < V; i++) {
color[i] = i +
1
;
}
int
[] colored =
new
int
[V];
Arrays.fill(colored,
0
);
int
numvc =
0
;
int
k =
0
;
for
(
int
i =
0
; i < V; i++) {
if
(numvc == V) {
break
;
}
if
(colored[vorder[i]] !=
0
) {
continue
;
}
else
{
colored[vorder[i]] = color[k];
numvc++;
for
(
int
j =
0
; j < V; j++) {
if
(colored[j] ==
0
&& adj.get(vorder[i]).get(j) ==
0
) {
colored[j] = color[k];
numvc++;
}
}
k++;
}
}
Arrays.sort(colored);
int
unique_color =
1
;
for
(
int
i =
1
; i < V; i++) {
if
(colored[i] != colored[i -
1
]) {
unique_color++;
}
}
return
unique_color;
}
public
static
void
main(String[] args)
{
int
V =
7
;
int
E =
12
;
int
Edges[][] = { {
0
,
1
}, {
0
,
3
}, {
0
,
4
}, {
0
,
6
}, {
1
,
2
}, {
1
,
4
}, {
1
,
6
}, {
2
,
5
}, {
2
,
6
}, {
3
,
4
}, {
3
,
5
}, {
4
,
5
} };
System.out.println(minimumDays(V, Edges, E));
}
}
class
Pair<L, R> {
L first;
R second;
public
Pair(L first, R second) {
this
.first = first;
this
.second = second;
}
}