結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | bluemegane |
提出日時 | 2021-04-11 11:26:42 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,111 bytes |
コンパイル時間 | 2,437 ms |
コンパイル使用メモリ | 108,160 KB |
実行使用メモリ | 46,452 KB |
最終ジャッジ日時 | 2024-06-27 07:07:59 |
合計ジャッジ時間 | 15,752 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
19,328 KB |
testcase_01 | AC | 32 ms
19,456 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 291 ms
43,120 KB |
testcase_23 | AC | 260 ms
41,720 KB |
testcase_24 | AC | 238 ms
40,440 KB |
testcase_25 | AC | 282 ms
42,480 KB |
testcase_26 | AC | 283 ms
42,984 KB |
testcase_27 | AC | 128 ms
30,720 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 214 ms
37,504 KB |
testcase_37 | AC | 229 ms
40,184 KB |
testcase_38 | AC | 67 ms
25,216 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 e0 = new List<int>(); foreach (var x in aa[0]) e0.Add(x.to); var W = getW(e2s, e0); var step = getSTEP(aa, W); Console.WriteLine("{0} {1}", W, step); } static int getW(E2[] e2s, List<int> e0) { var uf = new UnionFind(n); e2s = e2s.OrderByDescending(x => x.d).ToArray(); uf.Unite(e2s[0].n1, e2s[0].n2); var p = uf.Root(e2s[0].n1); for (int i = 1; i < m; i++) { uf.Unite(p, e2s[i].n1); uf.Unite(p, e2s[i].n2); foreach (var x in e0) { if (uf.Root(x) == p) return e2s[i].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; } }