using
System;
using
System.Collections.Generic;
class
GFG
{
static
void
minMax(
int
[,]edges,
int
len,
int
n)
{
Dictionary<
int
,
int
> m =
new
Dictionary<
int
,
int
>();
for
(
int
i = 0; i < len; i++)
{
if
(m.ContainsKey(edges[i, 0]))
{
m[edges[i, 0]] = m[edges[i, 0]] + 1;
}
else
{
m.Add(edges[i, 0], 1);
}
if
(m.ContainsKey(edges[i, 1]))
{
m[edges[i, 1]] = m[edges[i, 1]] + 1;
}
else
{
m.Add(edges[i, 1], 1);
}
}
int
maxi = 0;
int
mini = n;
for
(
int
i = 1; i <= n; i++)
{
maxi = Math.Max(maxi, m[i]);
mini = Math.Min(mini, m[i]);
}
Console.Write(
"Nodes with maximum degree : "
);
for
(
int
i = 1; i <= n; i++)
{
if
(m[i] == maxi)
Console.Write(i +
" "
);
}
Console.WriteLine();
Console.Write(
"Nodes with minimum degree : "
);
for
(
int
i = 1; i <= n; i++)
{
if
(m[i] == mini)
Console.Write(i +
" "
);
}
}
public
static
void
Main(String[] args)
{
int
m = 6;
int
[,]edges = {{ 1, 2 }, { 1, 3 },
{ 1, 4 }, { 2, 3 },
{ 2, 4 }, { 3, 4 }};
minMax(edges, m, 4);
}
}