結果
問題 | No.2630 Colorful Vertices and Cheapest Paths |
ユーザー | tobisatis |
提出日時 | 2024-02-16 22:31:59 |
言語 | C# (.NET 8.0.203) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,009 bytes |
コンパイル時間 | 7,895 ms |
コンパイル使用メモリ | 167,616 KB |
実行使用メモリ | 361,420 KB |
最終ジャッジ日時 | 2024-09-28 21:07:13 |
合計ジャッジ時間 | 48,488 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 804 ms
72,340 KB |
testcase_01 | AC | 1,800 ms
115,364 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 59 ms
31,232 KB |
testcase_04 | AC | 59 ms
31,616 KB |
testcase_05 | AC | 60 ms
31,076 KB |
testcase_06 | AC | 1,630 ms
54,144 KB |
testcase_07 | TLE | - |
testcase_08 | AC | 2,463 ms
179,448 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | AC | 922 ms
37,120 KB |
testcase_16 | AC | 911 ms
37,120 KB |
testcase_17 | AC | 935 ms
37,076 KB |
testcase_18 | AC | 1,785 ms
82,636 KB |
testcase_19 | AC | 2,130 ms
162,176 KB |
testcase_20 | AC | 2,010 ms
137,472 KB |
testcase_21 | AC | 2,204 ms
361,420 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (95 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
namespace AtCoder; #nullable enable using System.Numerics; class UnionFind { (int parent, int size, int edges)[] Verticals { get; set; } public UnionFind(int verticals) { Verticals = new (int, int, int)[verticals]; for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1, 0); } public int Union(int x, int y) { (x, y) = (Find(x), Find(y)); if (Size(x) < Size(y)) (x, y) = (y, x); Verticals[x].edges += 1; if (x == y) return x; Verticals[x].edges += Verticals[y].edges; Verticals[x].size += Verticals[y].size; Verticals[y].parent = x; return x; } public int Find(int x) => Parent(x).parent; public int Size(int x) => Parent(x).size; public int Edges(int x) => Parent(x).edges; (int parent, int size, int edges) Parent(int x) { var parentId = Verticals[x].parent; if (parentId == x) return Verticals[x]; var parent = Parent(parentId); Verticals[x].parent = parent.parent; return parent; } } static class Extensions { public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); public static int ToFlag(this int i) { if (i < 0 || 32 <= i) throw new IndexOutOfRangeException(); return 1 << i; } public static bool OfFlag(this int value, int i) => (value & ToFlag(i)) > 0; public static int WithFlag(this int value, int i, bool f) => f ? (value | ToFlag(i)) : (value & ~ToFlag(i)); } class AtCoder { object? Solve() { var n = Int(); var m = Int(); var edges = m.Repeat(() => (Int() - 1, Int() - 1)); var cz = n.Repeat(() => Int() - 1); var wz = 10.Repeat(() => Int()); var q = Int(); var ans = new long[q]; var b = 1 << 10; var ufz = b.Repeat(() => new UnionFind(n)); var csumz = new long[b]; for (var i = 0; i < b; i++) { var csum = 0L; for (var j = 0; j < 10; j++) if (i.OfFlag(j)) csum += wz[j]; csumz[i] = csum; } for (var i = 0; i < b; i++) { foreach (var (u, v) in edges) { if (!i.OfFlag(cz[u]) || !i.OfFlag(cz[v])) continue; ufz[i].Union(u, v); } } for (var t = 0; t < q; t++) { var u = Int() - 1; var v = Int() - 1; var minc = long.MaxValue; for (var i = 0; i < b; i++) { if (ufz[i].Find(u) == ufz[i].Find(v)) minc = Math.Min(minc, csumz[i]); } if (minc == long.MaxValue) minc = -1; ans[t] = minc; } Out(ans); return null; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty<string>(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; #pragma warning disable IDE0051 string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input<T>() where T : IParsable<T> => T.Parse(String(), null); int Int() => Input<int>(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } #pragma warning restore IDE0051 }