結果

問題 No.1473 おでぶなおばけさん
ユーザー bluemeganebluemegane
提出日時 2021-04-11 13:20:44
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 2,805 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 68,304 KB
実行使用メモリ 50,960 KB
最終ジャッジ日時 2023-09-09 15:48:39
合計ジャッジ時間 16,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
24,004 KB
testcase_01 AC 68 ms
21,960 KB
testcase_02 AC 376 ms
48,072 KB
testcase_03 AC 314 ms
47,108 KB
testcase_04 AC 205 ms
39,628 KB
testcase_05 AC 112 ms
28,872 KB
testcase_06 AC 335 ms
48,044 KB
testcase_07 AC 393 ms
50,960 KB
testcase_08 AC 410 ms
49,048 KB
testcase_09 AC 393 ms
50,948 KB
testcase_10 AC 253 ms
42,280 KB
testcase_11 AC 252 ms
42,116 KB
testcase_12 AC 252 ms
42,964 KB
testcase_13 AC 186 ms
37,336 KB
testcase_14 AC 152 ms
34,452 KB
testcase_15 AC 232 ms
39,956 KB
testcase_16 AC 239 ms
42,684 KB
testcase_17 AC 80 ms
24,072 KB
testcase_18 AC 92 ms
27,216 KB
testcase_19 AC 222 ms
39,908 KB
testcase_20 AC 268 ms
42,060 KB
testcase_21 AC 316 ms
43,588 KB
testcase_22 AC 309 ms
47,320 KB
testcase_23 AC 269 ms
45,080 KB
testcase_24 AC 263 ms
44,632 KB
testcase_25 AC 312 ms
44,692 KB
testcase_26 AC 308 ms
45,292 KB
testcase_27 AC 154 ms
33,512 KB
testcase_28 AC 374 ms
50,512 KB
testcase_29 AC 269 ms
42,352 KB
testcase_30 AC 326 ms
46,680 KB
testcase_31 AC 376 ms
50,028 KB
testcase_32 AC 341 ms
48,652 KB
testcase_33 AC 266 ms
41,928 KB
testcase_34 AC 158 ms
33,564 KB
testcase_35 AC 184 ms
36,584 KB
testcase_36 AC 240 ms
42,000 KB
testcase_37 AC 241 ms
41,720 KB
testcase_38 AC 100 ms
25,956 KB
testcase_39 AC 245 ms
41,912 KB
testcase_40 AC 243 ms
41,928 KB
testcase_41 AC 237 ms
38,964 KB
testcase_42 AC 235 ms
37,084 KB
testcase_43 AC 268 ms
49,668 KB
testcase_44 AC 266 ms
43,684 KB
testcase_45 AC 265 ms
45,628 KB
testcase_46 AC 269 ms
42,908 KB
testcase_47 AC 333 ms
42,600 KB
testcase_48 AC 296 ms
44,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
    public int getMem(int x) => -data[Root(x)];
}

public class E2
{
    public int n1 { get; set; }
    public int n2 { get; set; }
    public int d { get; set; }
}


public class Edge
{
    public int to { get; set; }
    public int d { get; set; }
}

public class P
{
    public int from { get; set; }
    public int step { get; set; }
}

public class Hello
{
    public static int n, m;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(line[0]);
        m = int.Parse(line[1]);
        var aa = new List<Edge>[n];
        for (int i = 0; i < n; i++) aa[i] = new List<Edge>();
        var e2s = new E2[m];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]) - 1;
            var t = int.Parse(line[1]) - 1;
            var d = int.Parse(line[2]);
            aa[s].Add(new Edge { to = t, d = d });
            aa[t].Add(new Edge { to = s, d = d });
            e2s[i] = new E2 { n1 = s, n2 = t, d = d };
        }
        var W = getW(e2s);
        var step = getSTEP(aa, W);
        Console.WriteLine("{0} {1}", W, step);
    }
    static int getW(E2[] e2s)
    {
        var uf = new UnionFind(n);
        foreach( var x in e2s.OrderByDescending(x =>x.d))
        {
            uf.Unite(x.n1, x.n2);
            if (uf.Root(n - 1) == uf.Root(0)) return x.d;
        }
        return 0;
    }

    static int getSTEP(List<Edge>[] aa, int t)
    {
        var visited = new bool[n];
        var q = new Queue<P>();
        q.Enqueue(new P { from = 0, step = 0 });
        visited[0] = true;
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.from == n - 1) return w.step;
            foreach (var x in aa[w.from])
            {
                if (t <= x.d && !visited[x.to])
                {
                    q.Enqueue(new P { from = x.to, step = w.step + 1 });
                    visited[x.to] = true;
                }
            }
        }
        return 0;
    }
}
0