public void Solve() { int H = NextInt(), W = NextInt(); var wf = new WarshallFloyd(10); 10.REP(i => { 10.REP(j => { var cost = NextInt(); wf.Add(i, j, cost); }); }); var res = wf.Run(); var ans = 0L; H.REP(i => W.REP(j => { var q = NextInt(); if (q == -1 || q == 1) { return; } ans += res[q][1]; })); ans.WL(); return; }
public void Solve() { // ABC079 D int H = NextInt(), W = NextInt(); var wf = new WarshallFloyd(10); 10.REP(i => 10.REP(j => { var ci = NextInt(); wf.Add(i, j, ci); })); var res = wf.Run(); var ans = 0L; H.REP(i => { foreach (var item in NextIntList()) { if (item == -1 || item == 1) { continue; } ans += res[item][1]; } }); ans.WL(); return; }
public void Solve() { int N = NextInt(), M = NextInt(), R = NextInt(); var r = NextIntList().Select(x => x - 1).ToList(); var warshallFloyd = new WarshallFloyd(N); M.REP(i => { int ai = NextInt() - 1, bi = NextInt() - 1, ci = NextInt(); warshallFloyd.Add(ai, bi, ci, false); }); var res = warshallFloyd.Run(); var used = new bool[R]; R.REP(i => used[i] = false); Func <int, int, long, long> dfs = null; dfs = (from, step, distance) => { if (used[from]) { return(long.MaxValue); } if (step == R - 1) { return(distance); } var rt = long.MaxValue; used[from] = true; for (int i = 0; i < R; i++) { rt = Min(rt, dfs(i, step + 1, distance + res[r[from]][r[i]])); } used[from] = false; return(rt); }; var ans = Enumerable.Range(0, R).Select(i => dfs(i, 0, 0)).Min(); ans.WL(); }