結果
問題 | No.2630 Colorful Vertices and Cheapest Paths |
ユーザー | tobisatis |
提出日時 | 2024-02-16 22:36:34 |
言語 | C# (.NET 8.0.203) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,840 bytes |
コンパイル時間 | 8,355 ms |
コンパイル使用メモリ | 168,344 KB |
実行使用メモリ | 281,684 KB |
最終ジャッジ日時 | 2024-09-28 21:12:21 |
合計ジャッジ時間 | 45,148 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 665 ms
51,444 KB |
testcase_01 | AC | 1,560 ms
74,980 KB |
testcase_02 | AC | 2,413 ms
111,224 KB |
testcase_03 | AC | 63 ms
31,232 KB |
testcase_04 | AC | 62 ms
31,488 KB |
testcase_05 | AC | 63 ms
31,092 KB |
testcase_06 | AC | 1,062 ms
44,032 KB |
testcase_07 | AC | 2,310 ms
117,880 KB |
testcase_08 | AC | 2,342 ms
108,828 KB |
testcase_09 | AC | 2,389 ms
118,992 KB |
testcase_10 | AC | 2,482 ms
119,136 KB |
testcase_11 | AC | 2,485 ms
118,760 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 2,499 ms
118,772 KB |
testcase_14 | AC | 2,413 ms
119,128 KB |
testcase_15 | AC | 746 ms
35,708 KB |
testcase_16 | AC | 752 ms
35,708 KB |
testcase_17 | AC | 752 ms
35,968 KB |
testcase_18 | AC | 1,525 ms
57,472 KB |
testcase_19 | AC | 1,915 ms
97,608 KB |
testcase_20 | AC | 1,795 ms
85,912 KB |
testcase_21 | AC | 2,110 ms
281,684 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (97 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)[] Verticals { get; set; } public UnionFind(int verticals) { Verticals = new (int, int)[verticals]; for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1); } public int Union(int x, int y) { (x, y) = (Find(x), Find(y)); if (Size(x) < Size(y)) (x, y) = (y, x); if (x == y) return x; 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; (int parent, int size) 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 }