using
System;
using
System.Collections.Generic;
using
System.Linq;
class
MainClass {
static
int
Max, sMax;
static
int
cnt = 0;
static
void
dfs(
int
u,
int
N, List<
bool
> vis,
List<List<
int
> > adj)
{
if
(u > Max) {
sMax = Max;
Max = u;
}
else
if
(u > sMax) {
sMax = u;
}
cnt++;
vis[u] =
true
;
for
(
int
i = 0; i < adj[u].Count; i++) {
int
to = adj[u][i];
if
(!vis[to]) {
dfs(to, N, vis, adj);
}
}
return
;
}
static
int
MaximumProduct(
int
N,
List<Tuple<
int
,
int
> > Edge,
List<
int
> wt)
{
int
M = wt.Count;
Dictionary<
int
, List<Tuple<
int
,
int
> > > mp
=
new
Dictionary<
int
,
List<Tuple<
int
,
int
> > >();
for
(
int
i = 0; i < M; i++) {
if
(!mp.ContainsKey(wt[i])) {
mp.Add(wt[i],
new
List<Tuple<
int
,
int
> >());
}
mp[wt[i]].Add(Edge[i]);
}
var
keys = mp.Keys.ToList();
keys.Sort();
keys.Reverse();
int
res = 0;
foreach
(
var
i
in
keys)
{
List<List<
int
> > adj =
new
List<List<
int
> >();
for
(
int
j = 0; j <= N; j++)
adj.Add(
new
List<
int
>());
List<Tuple<
int
,
int
> > v = mp[i];
for
(
int
j = 0; j < v.Count; j++) {
int
U = v[j].Item1;
int
V = v[j].Item2;
adj[U].Add(V);
adj[V].Add(U);
}
List<
bool
> vis =
new
List<
bool
>();
for
(
int
j = 0; j <= N; j++)
vis.Add(
false
);
int
cntMax = 0;
for
(
int
u = 1; u <= N; u++) {
Max = 0;
sMax = 0;
cnt = 0;
if
(!vis[u]) {
dfs(u, N, vis, adj);
if
(cnt > cntMax) {
res = Max * sMax;
cntMax = cnt;
}
else
if
(cnt == cntMax) {
res = Math.Max(res, Max * sMax);
}
}
}
}
return
res;
}
public
static
void
Main(
string
[] args)
{
int
N = 5;
List<Tuple<
int
,
int
> > Edges
=
new
List<Tuple<
int
,
int
> >();
Edges.Add(Tuple.Create(1, 2));
Edges.Add(Tuple.Create(2, 5));
Edges.Add(Tuple.Create(3, 5));
Edges.Add(Tuple.Create(4, 5));
Edges.Add(Tuple.Create(1, 2));
Edges.Add(Tuple.Create(2, 3));
Edges.Add(Tuple.Create(3, 4));
List<
int
> Weight
=
new
List<
int
>{ 1, 1, 1, 1, 2, 2, 2 };
Console.WriteLine(MaximumProduct(N, Edges, Weight));
}
}