結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 WA * 38 |
コンパイルメッセージ
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; } }