結果
| 問題 | 
                            No.2642 Don't cut line!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-02-19 22:24:30 | 
| 言語 | C#  (.NET 8.0.404)  | 
                    
| 結果 | 
                             
                                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 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 WA * 1 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /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
}