結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー |
|
提出日時 | 2023-02-03 21:41:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 380 ms / 2,000 ms |
コード長 | 1,507 bytes |
コンパイル時間 | 2,322 ms |
コンパイル使用メモリ | 107,520 KB |
実行使用メモリ | 75,392 KB |
最終ジャッジ日時 | 2024-07-02 19:31:13 |
合計ジャッジ時間 | 8,090 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { 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(); public 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>[n]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List<int>(); foreach (var edge in map) { tree[edge[0]].Add(edge[1]); tree[edge[1]].Add(edge[0]); } var colors = new int[n]; for (var i = 0; i < n; ++i) { if (DFS(i, 1, tree, colors)) { WriteLine("No"); return; } } WriteLine("Yes"); } static bool DFS(int cur, int color, List<int>[] tree, int[] colors) { colors[cur] = color; foreach (var next in tree[cur]) { if (colors[next] != 0) { if (colors[cur] == colors[next]) return false; } else { if (!DFS(next, -color, tree, colors)) return false; } } return true; } }