結果
問題 | No.1640 簡単な色塗り |
ユーザー | kakel-san |
提出日時 | 2021-08-06 23:01:03 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 241 ms / 2,000 ms |
コード長 | 2,947 bytes |
コンパイル時間 | 2,327 ms |
コンパイル使用メモリ | 114,308 KB |
実行使用メモリ | 44,280 KB |
最終ジャッジ日時 | 2024-06-29 16:08:54 |
合計ジャッジ時間 | 17,953 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
19,200 KB |
testcase_01 | AC | 28 ms
19,328 KB |
testcase_02 | AC | 29 ms
19,328 KB |
testcase_03 | AC | 30 ms
19,456 KB |
testcase_04 | AC | 194 ms
44,152 KB |
testcase_05 | AC | 197 ms
44,280 KB |
testcase_06 | AC | 31 ms
19,200 KB |
testcase_07 | AC | 29 ms
19,328 KB |
testcase_08 | AC | 29 ms
19,072 KB |
testcase_09 | AC | 28 ms
19,328 KB |
testcase_10 | AC | 144 ms
35,188 KB |
testcase_11 | AC | 118 ms
32,128 KB |
testcase_12 | AC | 105 ms
30,200 KB |
testcase_13 | AC | 207 ms
40,320 KB |
testcase_14 | AC | 218 ms
40,448 KB |
testcase_15 | AC | 84 ms
26,496 KB |
testcase_16 | AC | 93 ms
27,904 KB |
testcase_17 | AC | 172 ms
37,620 KB |
testcase_18 | AC | 45 ms
23,936 KB |
testcase_19 | AC | 107 ms
30,080 KB |
testcase_20 | AC | 141 ms
34,560 KB |
testcase_21 | AC | 115 ms
32,384 KB |
testcase_22 | AC | 40 ms
22,500 KB |
testcase_23 | AC | 165 ms
34,816 KB |
testcase_24 | AC | 59 ms
24,192 KB |
testcase_25 | AC | 108 ms
30,076 KB |
testcase_26 | AC | 160 ms
35,968 KB |
testcase_27 | AC | 85 ms
27,008 KB |
testcase_28 | AC | 213 ms
38,900 KB |
testcase_29 | AC | 155 ms
36,472 KB |
testcase_30 | AC | 54 ms
24,320 KB |
testcase_31 | AC | 197 ms
37,748 KB |
testcase_32 | AC | 171 ms
34,940 KB |
testcase_33 | AC | 119 ms
30,080 KB |
testcase_34 | AC | 147 ms
32,384 KB |
testcase_35 | AC | 123 ms
30,464 KB |
testcase_36 | AC | 51 ms
24,192 KB |
testcase_37 | AC | 73 ms
26,240 KB |
testcase_38 | AC | 195 ms
37,364 KB |
testcase_39 | AC | 87 ms
26,752 KB |
testcase_40 | AC | 85 ms
26,112 KB |
testcase_41 | AC | 153 ms
35,456 KB |
testcase_42 | AC | 96 ms
28,032 KB |
testcase_43 | AC | 95 ms
27,264 KB |
testcase_44 | AC | 94 ms
27,776 KB |
testcase_45 | AC | 83 ms
28,416 KB |
testcase_46 | AC | 53 ms
23,552 KB |
testcase_47 | AC | 49 ms
23,328 KB |
testcase_48 | AC | 193 ms
36,340 KB |
testcase_49 | AC | 37 ms
22,272 KB |
testcase_50 | AC | 29 ms
19,200 KB |
testcase_51 | AC | 29 ms
19,584 KB |
testcase_52 | AC | 238 ms
44,140 KB |
testcase_53 | AC | 241 ms
44,136 KB |
07_evil_01.txt | AC | 519 ms
62,556 KB |
07_evil_02.txt | AC | 859 ms
79,312 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using static System.Console; using System.Linq; class yuki308 { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray(); static void Main() { var n = NN; var map = NMap(n); for (var i = 0; i < n; ++i) { --map[i][0]; --map[i][1]; Array.Sort(map[i]); } var p = new Pair[n]; for (var i = 0; i < p.Length; ++i) p[i] = new Pair(i); for (var i = 0; i < map.Length; ++i) { p[map[i][0]].Edges.Add(i); p[map[i][1]].Edges.Add(i); } var used = new bool[n]; var res = new int[n]; for (var i = 0; i < p.Length; ++i) { var cur = i; while (p[cur].Edges.Count == 1) { var paint = p[cur].Edges[0]; res[paint] = cur + 1; used[cur] = true; p[map[paint][0]].Edges.Remove(paint); p[map[paint][1]].Edges.Remove(paint); cur = cur ^ (map[paint][0]) ^ (map[paint][1]); } } for (var i = 0; i < p.Length; ++i) { var cur = i; while (p[cur].Edges.Count > 0) { var paint = p[cur].Edges[0]; res[paint] = cur + 1; used[cur] = true; p[map[paint][0]].Edges.Remove(paint); p[map[paint][1]].Edges.Remove(paint); cur = cur ^ (map[paint][0]) ^ (map[paint][1]); } } if (used.Count(f => !f) == 0) { WriteLine("Yes"); WriteLine(string.Join("\n", res)); } else WriteLine("No"); } class Pair { public List<int> Edges = new List<int>(); public int Num; public Pair(int num) { Num = num; } } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); 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)]; } } }