static void Main() { var(n, m) = Read2(); var map = GraphConsole.ReadWeightedMap(n + 1, m, true); var r = new long[n + 1]; for (int ev = 1; ev <= n; ev++) { var result = ShortestPathCore.Dijkstra(n + 1, v => v == 0 ? map[ev] : map[v], 0, ev); r[ev] = result.GetCost(ev); } Console.WriteLine(string.Join("\n", r[1..]));
static void Main() { var(n, m) = Read2(); var es = Array.ConvertAll(new bool[m], _ => Read()); var map = EdgesToMap2(n + 1, es, false); // 辺を静的に構築すると MLE。 var r = ShortestPathCore.Dijkstra(n + 1, 51, v => { if (v.j == 0) { return(Array.ConvertAll(map[v.i].ToArray(), e => new Edge(v, (e[1], e[2]), 0))); }
static object Solve() { var(h, w) = Read2(); var a = GraphConsole.ReadIntGrid(h); var b = GraphConsole.ReadIntGrid(h - 1); Point sv = (0, 0); Point ev = (h - 1, w - 1); var r = ShortestPathCore.Dijkstra(h * 2, w, v => { var es = new List <Edge>(); if (v.i < h) { if (v.j < w - 1) { es.Add(new Edge(v, v + (0, 1), a[v]));
static void Main() { var(n, m) = Read2(); var es = Array.ConvertAll(new bool[m], _ => (Edge)Read()); var map = new WeightedMap(n + 1, es, false); var id = n; var idMap = new int[n + 1, 51]; var idMap_r = new List <(int v, long w)>(Enumerable.Range(0, n + 1).Select(i => (i, 0L))); void InitId(int v, long w) { if (idMap[v, w] != 0) { return; } idMap[v, w] = ++id; idMap_r.Add((v, w)); } foreach (var(v, u, w) in es) { InitId(v, w); InitId(u, w); } // 辺を静的に構築すると MLE。 var r = ShortestPathCore.Dijkstra(id + 1, v => { if (v <= n) { return(Array.ConvertAll(map[v], e => new Edge(v, idMap[e.To, e.Cost], 0))); } else { var(v0, w) = idMap_r[v]; return(Array.ConvertAll(map[v0], e => new Edge(v, e.To, (w + e.Cost) * (w + e.Cost)))); } }, 1); Console.WriteLine(string.Join(" ", Enumerable.Range(1, n).Select(v => r.GetCost(v)))); }
public WeightedResult Dijkstra(int startVertex, int endVertex = -1) { return(ShortestPathCore.Dijkstra(VertexesCount, v => this[v], startVertex, endVertex)); }
public WeightedResult Dijkstra(Point startVertex, Point endVertex) { return(ShortestPathCore.Dijkstra(Height, Width, v => this[v], startVertex, endVertex)); }