結果
問題 | No.2072 Anatomy |
ユーザー |
|
提出日時 | 2022-09-16 23:07:22 |
言語 | C#(mono) (mono 6.12.0.158) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 2,652 bytes |
コンパイル時間 | 1,074 ms |
使用メモリ | 78,384 KB |
最終ジャッジ日時 | 2023-01-11 08:23:10 |
合計ジャッジ時間 | 11,276 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
21,908 KB |
testcase_01 | AC | 63 ms
22,088 KB |
testcase_02 | AC | 64 ms
20,020 KB |
testcase_03 | AC | 64 ms
22,032 KB |
testcase_04 | AC | 64 ms
21,944 KB |
testcase_05 | AC | 64 ms
21,996 KB |
testcase_06 | AC | 65 ms
21,908 KB |
testcase_07 | AC | 63 ms
22,056 KB |
testcase_08 | AC | 341 ms
49,196 KB |
testcase_09 | AC | 342 ms
73,332 KB |
testcase_10 | AC | 343 ms
61,004 KB |
testcase_11 | AC | 348 ms
69,436 KB |
testcase_12 | AC | 297 ms
63,244 KB |
testcase_13 | AC | 375 ms
50,168 KB |
testcase_14 | AC | 258 ms
51,300 KB |
testcase_15 | AC | 225 ms
52,364 KB |
testcase_16 | AC | 362 ms
54,288 KB |
testcase_17 | AC | 354 ms
76,660 KB |
testcase_18 | AC | 204 ms
51,636 KB |
testcase_19 | AC | 396 ms
50,532 KB |
testcase_20 | AC | 420 ms
50,520 KB |
testcase_21 | AC | 352 ms
78,384 KB |
testcase_22 | AC | 388 ms
52,892 KB |
testcase_23 | AC | 362 ms
76,428 KB |
testcase_24 | AC | 353 ms
76,496 KB |
testcase_25 | AC | 369 ms
50,324 KB |
testcase_26 | AC | 63 ms
24,072 KB |
testcase_27 | AC | 362 ms
76,492 KB |
testcase_28 | AC | 332 ms
52,352 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)]; } } }