結果

問題 No.2618 除霊
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-26 22:23:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 1,955 bytes
コンパイル時間 8,613 ms
コンパイル使用メモリ 156,916 KB
実行使用メモリ 243,084 KB
最終ジャッジ日時 2024-01-26 22:23:51
合計ジャッジ時間 26,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
33,188 KB
testcase_01 AC 82 ms
33,188 KB
testcase_02 AC 83 ms
33,188 KB
testcase_03 AC 81 ms
33,188 KB
testcase_04 AC 81 ms
33,188 KB
testcase_05 AC 83 ms
33,188 KB
testcase_06 AC 394 ms
78,192 KB
testcase_07 AC 413 ms
78,320 KB
testcase_08 AC 405 ms
85,540 KB
testcase_09 AC 384 ms
83,032 KB
testcase_10 AC 416 ms
95,472 KB
testcase_11 AC 352 ms
80,168 KB
testcase_12 AC 441 ms
85,160 KB
testcase_13 AC 315 ms
77,824 KB
testcase_14 AC 383 ms
90,628 KB
testcase_15 AC 348 ms
78,264 KB
testcase_16 AC 329 ms
79,116 KB
testcase_17 AC 367 ms
83,072 KB
testcase_18 AC 408 ms
87,812 KB
testcase_19 AC 334 ms
78,660 KB
testcase_20 AC 329 ms
78,040 KB
testcase_21 AC 362 ms
82,472 KB
testcase_22 AC 397 ms
92,300 KB
testcase_23 AC 343 ms
78,664 KB
testcase_24 AC 361 ms
78,828 KB
testcase_25 AC 367 ms
83,852 KB
testcase_26 AC 371 ms
88,592 KB
testcase_27 AC 356 ms
78,712 KB
testcase_28 AC 333 ms
77,956 KB
testcase_29 AC 363 ms
83,068 KB
testcase_30 AC 422 ms
91,536 KB
testcase_31 AC 401 ms
86,136 KB
testcase_32 AC 366 ms
71,116 KB
testcase_33 AC 407 ms
76,264 KB
testcase_34 AC 380 ms
77,896 KB
testcase_35 AC 377 ms
82,084 KB
testcase_36 AC 435 ms
84,948 KB
testcase_37 AC 397 ms
85,364 KB
testcase_38 AC 413 ms
87,488 KB
testcase_39 AC 407 ms
83,204 KB
testcase_40 AC 413 ms
90,060 KB
testcase_41 AC 455 ms
94,476 KB
testcase_42 AC 414 ms
243,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (103 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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[] 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 n = NN;
        var map = NMap(n - 1);
        var m = NN;
        var v = NMi;

        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 g = new bool[n];
        foreach (var vi in v) g[vi] = true;
        var nx = new int[n];
        for (var i = 0; i < n; ++i)
        {
            foreach (var next in tree[i]) if (g[next]) ++nx[i];
        }

        var olist = (bool[]) g.Clone();
        for (var i = 0; i < n; ++i) if (g[i]) foreach (var next in tree[i]) olist[next] = true;
        var org = olist.Count(f => f);

        var rem = new int[n];
        for (var i = 0; i < n; ++i)
        {
            foreach (var n2 in tree[i])
            {
                if (!g[n2] && g[i] && nx[n2] == 1) ++rem[i];
            }
        }
        var ans = Enumerable.Repeat(org, n).ToArray();
        for (var i = 0; i < n; ++i)
        {
            if (g[i] || nx[i] > 0) --ans[i];
            foreach (var n1 in tree[i])
            {
                if ((g[n1] || nx[n1] > 0) && nx[n1] == (g[i] ? 1 : 0)) --ans[i];
                ans[i] -= rem[n1];
                if (!g[i] && g[n1] && nx[i] == 1) ++ans[i];
            }
        }
        WriteLine(string.Join("\n", ans));
    }
}
0