using
System;
using
System.Linq;
using
System.Collections.Generic;
public
class
GFG{
static
int
inf = 100000000;
public
static
int
smPath(
int
s,
int
d,
List<KeyValuePair<KeyValuePair<
int
,
int
>,
int
>> ed,
int
n,
int
k)
{
int
[]dis = Enumerable.Repeat(inf, n+1).ToArray();
dis[s] = 0;
for
(
int
i = 0; i < k; i++)
{
int
[]dis1 = Enumerable.Repeat(inf, n+1).ToArray();
foreach
(KeyValuePair<KeyValuePair<
int
,
int
>,
int
> it
in
ed)
dis1[it.Key.Value] = Math.Min(dis1[it.Key.Value],
dis[it.Key.Key] +
it.Value);
for
(
int
j = 0; j <= n; j++)
dis[j] = dis1[j];
}
if
(dis[d] == inf)
return
-1;
else
return
dis[d];
}
public
static
void
Main(
string
[] args)
{
int
n = 4;
List<KeyValuePair<KeyValuePair<
int
,
int
>,
int
>> ed =
new
List<KeyValuePair<KeyValuePair<
int
,
int
>,
int
>>(){
new
KeyValuePair<KeyValuePair<
int
,
int
>,
int
>(
new
KeyValuePair<
int
,
int
>(0, 1), 10),
new
KeyValuePair<KeyValuePair<
int
,
int
>,
int
>(
new
KeyValuePair<
int
,
int
>(0, 2), 3),
new
KeyValuePair<KeyValuePair<
int
,
int
>,
int
>(
new
KeyValuePair<
int
,
int
>(0, 3), 2),
new
KeyValuePair<KeyValuePair<
int
,
int
>,
int
>(
new
KeyValuePair<
int
,
int
>(1, 3), 7),
new
KeyValuePair<KeyValuePair<
int
,
int
>,
int
>(
new
KeyValuePair<
int
,
int
>(2, 3), 7)
};
int
s = 0, d = 3;
int
k = 2;
Console.Write(smPath(s, d, ed, n, k));
}
}