using
System;
using
System.Collections.Generic;
class
Program
{
static
int
V = 5;
static
void
PrintPath(
int
[] parent,
int
vertex,
int
target)
{
if
(vertex == 0)
{
return
;
}
PrintPath(parent, parent[vertex], target);
Console.Write(vertex + (vertex == target ?
"\n"
:
"--"
));
}
static
int
WidestPathProblem(List<Tuple<
int
,
int
>>[] Graph,
int
src,
int
target)
{
int
[] widest =
new
int
[V];
for
(
int
i = 0; i < V; i++)
{
widest[i] = -1000000000;
}
int
[] parent =
new
int
[V];
List<Tuple<
int
,
int
>> container =
new
List<Tuple<
int
,
int
>>();
container.Add(
new
Tuple<
int
,
int
>(0, src));
widest[src] = 1000000000;
container.Sort((x, y) => y.Item1.CompareTo(x.Item1));
while
(container.Count > 0)
{
Tuple<
int
,
int
> temp = container[container.Count - 1];
int
current_src = temp.Item2;
container.RemoveAt(container.Count - 1);
foreach
(Tuple<
int
,
int
> vertex
in
Graph[current_src])
{
int
distance = Math.Max(widest[vertex.Item2], Math.Min(widest[current_src], vertex.Item1));
if
(distance > widest[vertex.Item2])
{
widest[vertex.Item2] = distance;
parent[vertex.Item2] = current_src;
container.Add(
new
Tuple<
int
,
int
>(distance, vertex.Item2));
container.Sort((x, y) => y.Item1.CompareTo(x.Item1));
}
}
}
PrintPath(parent, target, target);
return
widest[target];
}
static
void
Main(
string
[] args)
{
List<Tuple<
int
,
int
>>[] graph =
new
List<Tuple<
int
,
int
>>[V];
int
no_vertices = 4;
for
(
int
i = 0; i < V; i++)
{
graph[i] =
new
List<Tuple<
int
,
int
>>();
}
graph[1].Add(
new
Tuple<
int
,
int
>(1, 2));
graph[1].Add(
new
Tuple<
int
,
int
>(2, 4));
graph[2].Add(
new
Tuple<
int
,
int
>(3, 3));
graph[4].Add(
new
Tuple<
int
,
int
>(5, 3));
Console.WriteLine(WidestPathProblem(graph, 1, 3));
}
}