結果
問題 | No.2642 Don't cut line! |
ユーザー | tobisatis |
提出日時 | 2024-02-19 22:24:30 |
言語 | C# (.NET 8.0.203) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,919 bytes |
コンパイル時間 | 10,229 ms |
コンパイル使用メモリ | 169,728 KB |
実行使用メモリ | 195,556 KB |
最終ジャッジ日時 | 2024-09-29 03:36:01 |
合計ジャッジ時間 | 19,083 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 295 ms
70,612 KB |
testcase_02 | AC | 278 ms
70,612 KB |
testcase_03 | AC | 276 ms
74,068 KB |
testcase_04 | AC | 301 ms
70,996 KB |
testcase_05 | AC | 294 ms
76,244 KB |
testcase_06 | AC | 181 ms
58,956 KB |
testcase_07 | AC | 188 ms
59,228 KB |
testcase_08 | AC | 188 ms
59,224 KB |
testcase_09 | AC | 187 ms
58,944 KB |
testcase_10 | AC | 186 ms
59,096 KB |
testcase_11 | AC | 183 ms
59,352 KB |
testcase_12 | AC | 187 ms
59,224 KB |
testcase_13 | AC | 185 ms
59,104 KB |
testcase_14 | AC | 186 ms
59,480 KB |
testcase_15 | AC | 187 ms
59,224 KB |
testcase_16 | AC | 230 ms
61,652 KB |
testcase_17 | AC | 271 ms
64,000 KB |
testcase_18 | AC | 294 ms
69,848 KB |
testcase_19 | AC | 235 ms
71,656 KB |
testcase_20 | AC | 182 ms
57,064 KB |
testcase_21 | AC | 175 ms
58,368 KB |
testcase_22 | AC | 214 ms
64,832 KB |
testcase_23 | AC | 280 ms
69,980 KB |
testcase_24 | AC | 172 ms
53,760 KB |
testcase_25 | AC | 174 ms
54,528 KB |
testcase_26 | AC | 186 ms
58,240 KB |
testcase_27 | AC | 207 ms
64,640 KB |
testcase_28 | AC | 267 ms
74,076 KB |
testcase_29 | AC | 179 ms
57,472 KB |
testcase_30 | AC | 176 ms
55,424 KB |
testcase_31 | AC | 237 ms
72,116 KB |
testcase_32 | AC | 177 ms
56,320 KB |
testcase_33 | AC | 59 ms
30,848 KB |
testcase_34 | AC | 62 ms
30,440 KB |
testcase_35 | AC | 62 ms
195,556 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (98 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; static class Extensions { public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } 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; } } class AtCoder { object? Solve() { var n = Int(); var k = Int(); var c = Input<long>(); var edges = new (int, int, int, int, bool)[k]; for (var i = 0; i < k; i++) { var u = Int() - 1; var v = Int() - 1; var w = Int(); var p = Int(); edges[i] = (w, p, u, v, false); } Array.Sort(edges); var ans = 0L; var minC = 0L; var uf = new UnionFind(n); var g = n.Repeat(() => new List<(int, int)>()); for (var i = 0; i < k; i++) { var (w, p, u, v, _) = edges[i]; if (uf.Find(u) != uf.Find(v)) { minC += w; uf.Union(u, v); edges[i].Item5 = true; g[u].Add((v, w)); g[v].Add((u, w)); ans = Math.Max(ans, p); } } if (minC > c) return -1; var f = new long[n]; void S(int v, int prev) { foreach (var (next, nw) in g[v]) { if (next == prev) continue; f[next] = Math.Max(f[next], nw); S(next, v); } } S(edges[0].Item3, -1); foreach (var (w, p, u, v, t) in edges) { if (t) continue; var max = Math.Max(f[u], f[v]); if (minC - max + w < c) ans = Math.Max(ans, p); } return ans; } 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 }