public static void Solve() { var(N, M) = Scanner.Scan <int, int>(); var position = Enumerable.Range(0, N + 1).ToArray(); var current = 0; for (var i = 0; i < M; i++) { var next = Scanner.Scan <int>(); (position[current], position[next]) = (position[next], position[current]); current = next; } var answer = position.Select((p, i) => (p, i)).ToArray(); Array.Sort(answer, (x, y) => x.p.CompareTo(y.p)); Printer.Print(answer.Skip(1).Select(x => x.i), "\n"); }
public static void Solve() { var N = Scanner.Scan <int>(); if (N <= 1) { Printer.Print(0); return; } var X = new int[N]; var Y = new int[N]; var T = new int[N]; var R = new int[N]; for (var i = 0; i < N; i++) { (X[i], Y[i], T[i], R[i]) = Scanner.Scan <int, int, int, int>(); } var G = new List <(int To, double Cost)> [N].Select(x => new List <(int To, double Cost)>()).ToArray();
public static void Solve() { var(first, last) = Scanner.Scan <string, string>(); if (first == last) { Printer.Print(0); Printer.Print(first); Printer.Print(last); return; } var N = Scanner.Scan <int>(); var W = new List <string>(); W.Add(first); for (var i = 0; i < N; i++) { var w = Scanner.Scan <string>(); if (w != first && w != last) { W.Add(w); } } W.Add(last); W = W.Distinct().ToList(); var G = new List <int> [W.Count].Select(x => new List <int>()).ToArray(); var length = first.Length; for (var i = 0; i < W.Count - 1; i++) { for (var j = i + 1; j < W.Count; j++) { if (i == j) { G[i][j] = 0; continue; } var count = 0; for (var k = 0; k < length && count < 2; k++) { if (W[i][k] != W[j][k]) { count++; } } if (count != 1) { continue; } G[i].Add(j); G[j].Add(i); } } var queue = new Queue <int>(); queue.Enqueue(0); var depths = Enumerable.Repeat(-1, W.Count).ToArray(); depths[0] = 0; var parent = new int[W.Count]; while (queue.Any()) { var current = queue.Dequeue(); foreach (var next in G[current]) { if (depths[next] != -1) { continue; } depths[next] = depths[current] + 1; parent[next] = current; queue.Enqueue(next); } } var answer = depths[^ 1];