結果
問題 | No.2072 Anatomy |
ユーザー | 👑 kakel-san |
提出日時 | 2022-09-16 23:07:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 393 ms / 2,000 ms |
コード長 | 2,652 bytes |
コンパイル時間 | 1,653 ms |
コンパイル使用メモリ | 66,232 KB |
実行使用メモリ | 80,440 KB |
最終ジャッジ日時 | 2023-08-23 16:33:18 |
合計ジャッジ時間 | 11,382 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
21,816 KB |
testcase_01 | AC | 63 ms
21,860 KB |
testcase_02 | AC | 65 ms
21,684 KB |
testcase_03 | AC | 64 ms
23,720 KB |
testcase_04 | AC | 64 ms
19,784 KB |
testcase_05 | AC | 64 ms
21,740 KB |
testcase_06 | AC | 63 ms
21,684 KB |
testcase_07 | AC | 63 ms
19,736 KB |
testcase_08 | AC | 353 ms
50,964 KB |
testcase_09 | AC | 350 ms
73,088 KB |
testcase_10 | AC | 358 ms
64,852 KB |
testcase_11 | AC | 355 ms
69,220 KB |
testcase_12 | AC | 303 ms
67,056 KB |
testcase_13 | AC | 392 ms
54,028 KB |
testcase_14 | AC | 260 ms
51,176 KB |
testcase_15 | AC | 228 ms
56,224 KB |
testcase_16 | AC | 378 ms
57,956 KB |
testcase_17 | AC | 363 ms
78,528 KB |
testcase_18 | AC | 201 ms
51,644 KB |
testcase_19 | AC | 383 ms
52,652 KB |
testcase_20 | AC | 393 ms
54,348 KB |
testcase_21 | AC | 357 ms
80,316 KB |
testcase_22 | AC | 389 ms
52,668 KB |
testcase_23 | AC | 365 ms
78,360 KB |
testcase_24 | AC | 351 ms
80,440 KB |
testcase_25 | AC | 384 ms
50,416 KB |
testcase_26 | AC | 63 ms
23,860 KB |
testcase_27 | AC | 364 ms
78,380 KB |
testcase_28 | AC | 337 ms
52,320 KB |
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var map = NMap(m); var tree = new List<int>[m]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List<int>(); var uf = new UnionFindTree(n); var isBridge = new bool[m]; for (var i = m - 1; i >= 0; --i) { var pa = uf.info[uf.GetRoot(map[i][0])]; var pb = uf.info[uf.GetRoot(map[i][1])]; if (pa != int.MaxValue) tree[i].Add(pa); if (pb != int.MaxValue && pb != pa) tree[i].Add(pb); uf.Unite(map[i][0], map[i][1], i); } var dep = new int[m]; DFS(0, tree, dep); WriteLine(dep.Max() + 1); } static void DFS(int cur, List<int>[] tree, int[] dep) { foreach (var next in tree[cur]) { dep[next] = dep[cur] + 1; DFS(next, tree, dep); } } class UnionFindTree { int[] roots; public int[] info; public UnionFindTree(int size) { roots = new int[size]; info = Enumerable.Repeat(int.MaxValue, size).ToArray(); for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; roots[a] = GetRoot(roots[a]); info[roots[a]] = Math.Min(info[roots[a]], info[a]); return roots[a]; } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b, int info) { var x = GetRoot(a); var y = GetRoot(b); this.info[x] = Math.Min(this.info[x], info); this.info[y] = Math.Min(this.info[y], info); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }