結果
問題 | No.2912 0次パーシステントホモロジー |
ユーザー | tobisatis |
提出日時 | 2024-10-04 21:54:55 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 3,821 bytes |
コンパイル時間 | 10,028 ms |
コンパイル使用メモリ | 167,100 KB |
実行使用メモリ | 240,456 KB |
最終ジャッジ日時 | 2024-10-04 21:55:09 |
合計ジャッジ時間 | 13,122 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
35,968 KB |
testcase_01 | AC | 55 ms
35,700 KB |
testcase_02 | AC | 54 ms
35,968 KB |
testcase_03 | AC | 55 ms
35,584 KB |
testcase_04 | AC | 54 ms
35,584 KB |
testcase_05 | AC | 56 ms
35,456 KB |
testcase_06 | AC | 56 ms
35,584 KB |
testcase_07 | AC | 54 ms
35,328 KB |
testcase_08 | AC | 55 ms
35,548 KB |
testcase_09 | AC | 60 ms
35,456 KB |
testcase_10 | AC | 55 ms
35,456 KB |
testcase_11 | AC | 54 ms
35,580 KB |
testcase_12 | AC | 57 ms
35,708 KB |
testcase_13 | AC | 65 ms
36,476 KB |
testcase_14 | AC | 63 ms
36,224 KB |
testcase_15 | AC | 70 ms
38,144 KB |
testcase_16 | AC | 108 ms
52,864 KB |
testcase_17 | AC | 131 ms
57,416 KB |
testcase_18 | AC | 154 ms
64,700 KB |
testcase_19 | AC | 209 ms
76,664 KB |
testcase_20 | AC | 232 ms
76,276 KB |
testcase_21 | AC | 206 ms
76,288 KB |
testcase_22 | AC | 208 ms
240,456 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (88 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 edgeCount)[] Verticals { get; set; } bool EnabledUndo { get; init; } Stack<(int v, (int parent, int edges))> Histories { get; init; } public UnionFind(int verticals, bool enableUndo = false) { Verticals = new (int, int)[verticals]; for (int i = 0; i < verticals; i++) Verticals[i] = (-1, 0); Histories = new(); EnabledUndo = enableUndo; } public int Union(int x, int y) { (x, y) = (Find(x), Find(y)); var (sx, sy) = (Size(x), Size(y)); if (sx < sy) (x, y, sy) = (y, x, sx); var (nx, ny) = (Verticals[x], Verticals[y]); Histories.Push((x, nx)); Histories.Push((y, ny)); if (x == y) nx.edgeCount += 1; else { ny.parent = x; nx.parent -= sy; nx.edgeCount += ny.edgeCount + 1; } (Verticals[y], Verticals[x]) = (ny, nx); return x; } public int Find(int x) { var pid = Verticals[x].parent; if (pid < 0) return x; var aid = Find(pid); if (!EnabledUndo) Verticals[x].parent = aid; return aid; } public int Size(int x) => -Verticals[Find(x)].parent; public int EdgeCount(int x) => Verticals[Find(x)].edgeCount; public bool Undo() { if (!EnabledUndo || Histories.Count == 0) return false; for (var i = 0; i < 2; i++) { var (v, h) = Histories.Pop(); Verticals[v] = h; } return true; } } static class Extensions { public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var n = Int(); var m = Int(); var k = 100000; var edges = (k + 1).Repeat(() => new List<(int, int)>()); for (var i = 0; i < m; i++) { var u = Int(); var v = Int(); var w = Int(); edges[w].Add((u, v)); } var uf = new UnionFind(n); var connected = 0; var kns = new int[k + 1]; for (var i = 0; i <= k; i++) { foreach (var (u, v) in edges[i]) { if (uf.Find(u) != uf.Find(v)) { connected++; uf.Union(u, v); } } kns[i] = n - connected; } var t = Int(); var ans = new int[t]; for (var i = 0; i < t; i++) ans[i] = kns[Int()]; 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 }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Trim().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(); } }