結果

問題 No.1477 Lamps on Graph
ユーザー kakel-sankakel-san
提出日時 2024-06-27 23:36:31
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,585 bytes
コンパイル時間 7,634 ms
コンパイル使用メモリ 166,764 KB
実行使用メモリ 227,108 KB
最終ジャッジ日時 2024-06-27 23:36:52
合計ジャッジ時間 15,888 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
31,104 KB
testcase_01 AC 62 ms
31,232 KB
testcase_02 AC 62 ms
31,360 KB
testcase_03 AC 63 ms
31,104 KB
testcase_04 AC 69 ms
31,232 KB
testcase_05 AC 63 ms
31,104 KB
testcase_06 AC 62 ms
31,232 KB
testcase_07 AC 62 ms
31,104 KB
testcase_08 AC 62 ms
31,360 KB
testcase_09 AC 62 ms
31,088 KB
testcase_10 AC 62 ms
31,104 KB
testcase_11 AC 63 ms
31,088 KB
testcase_12 AC 201 ms
65,740 KB
testcase_13 AC 156 ms
59,008 KB
testcase_14 AC 205 ms
66,560 KB
testcase_15 AC 140 ms
51,200 KB
testcase_16 AC 112 ms
43,648 KB
testcase_17 AC 109 ms
40,448 KB
testcase_18 AC 155 ms
58,112 KB
testcase_19 AC 150 ms
57,600 KB
testcase_20 AC 113 ms
44,032 KB
testcase_21 AC 143 ms
54,780 KB
testcase_22 AC 109 ms
41,728 KB
testcase_23 AC 150 ms
56,688 KB
testcase_24 AC 214 ms
69,336 KB
testcase_25 AC 126 ms
48,624 KB
testcase_26 AC 214 ms
70,144 KB
testcase_27 AC 144 ms
53,120 KB
testcase_28 AC 152 ms
55,936 KB
testcase_29 AC 163 ms
52,820 KB
testcase_30 AC 115 ms
44,928 KB
testcase_31 AC 110 ms
43,520 KB
testcase_32 AC 254 ms
75,136 KB
testcase_33 AC 255 ms
74,368 KB
testcase_34 AC 257 ms
75,136 KB
testcase_35 AC 243 ms
72,780 KB
testcase_36 AC 243 ms
72,392 KB
testcase_37 AC 231 ms
70,732 KB
testcase_38 AC 277 ms
71,424 KB
testcase_39 AC 245 ms
227,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (112 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var map = NArr(m);
        var k = NN;
        var b = NList;

        var vlist = new (int id, int a)[n];
        for (var i = 0; i < n; ++i) vlist[i] = (i, a[i]);
        Array.Sort(vlist, (l, r) => l.a.CompareTo(r.a));
        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] - 1].Add(edge[1] - 1);
            tree[edge[1] - 1].Add(edge[0] - 1);
        }
        var lamp = new bool[n];
        foreach (var bi in b) lamp[bi - 1] = true;
        var ans = new List<int>();
        foreach (var v in vlist)
        {
            if (lamp[v.id])
            {
                ans.Add(v.id);
                lamp[v.id] = false;
                foreach (var next in tree[v.id]) if (a[v.id] < a[next])
                {
                    lamp[next] = !lamp[next];
                }
            }
        }
        WriteLine(ans.Count);
        WriteLine(string.Join("\n", ans.Select(ai => ai + 1)));
    }
}
0