結果

問題 No.1477 Lamps on Graph
ユーザー さかぽん
提出日時 2021-04-16 22:38:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 3,330 ms
コンパイル使用メモリ 109,480 KB
実行使用メモリ 52,032 KB
最終ジャッジ日時 2024-07-03 02:51:56
合計ジャッジ時間 11,517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class B
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main()
	{
		var (n, m) = Read2();
		var a = Read();
		var es = Array.ConvertAll(new bool[m], _ => Read());
		var k = int.Parse(Console.ReadLine());
		var b = Read();

		var map = EdgesToMap1(n + 1, es, false);
		var u = new bool[n + 1];
		foreach (var v in b) u[v] = true;

		var r = new List<int>();

		foreach (var (x, v) in a.Select((x, i) => (x, i: i + 1)).OrderBy(t => t.x))
		{
			if (!u[v]) continue;

			r.Add(v);
			u[v] = false;

			foreach (var nv in map[v])
			{
				if (a[v - 1] < a[nv - 1])
				{
					u[nv] ^= true;
				}
			}
		}

		Console.WriteLine(r.Count);
		Console.WriteLine(string.Join("\n", r));
	}

	public static List<int>[] EdgesToMap1(int n, int[][] es, bool directed)
	{
		var map = Array.ConvertAll(new bool[n], _ => new List<int>());
		foreach (var e in es)
		{
			map[e[0]].Add(e[1]);
			if (!directed) map[e[1]].Add(e[0]);
		}
		return map;
	}
}
0