結果

問題 No.2618 除霊
ユーザー Re0denXRe0denX
提出日時 2024-01-29 00:12:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 214,108 KB
実行使用メモリ 45,332 KB
最終ジャッジ日時 2024-01-29 00:13:14
合計ジャッジ時間 14,766 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 213 ms
34,792 KB
testcase_07 AC 176 ms
34,660 KB
testcase_08 AC 209 ms
37,204 KB
testcase_09 AC 208 ms
35,836 KB
testcase_10 AC 218 ms
35,104 KB
testcase_11 AC 141 ms
31,756 KB
testcase_12 AC 209 ms
37,436 KB
testcase_13 AC 223 ms
44,464 KB
testcase_14 AC 168 ms
35,712 KB
testcase_15 AC 100 ms
28,640 KB
testcase_16 AC 110 ms
29,216 KB
testcase_17 AC 157 ms
37,648 KB
testcase_18 AC 203 ms
43,368 KB
testcase_19 AC 112 ms
30,076 KB
testcase_20 AC 103 ms
28,976 KB
testcase_21 AC 153 ms
35,952 KB
testcase_22 AC 194 ms
45,332 KB
testcase_23 AC 232 ms
44,160 KB
testcase_24 AC 233 ms
43,512 KB
testcase_25 AC 220 ms
40,444 KB
testcase_26 AC 177 ms
35,220 KB
testcase_27 AC 207 ms
43,172 KB
testcase_28 AC 219 ms
44,696 KB
testcase_29 AC 224 ms
40,452 KB
testcase_30 AC 231 ms
36,596 KB
testcase_31 AC 216 ms
37,532 KB
testcase_32 AC 130 ms
29,292 KB
testcase_33 AC 158 ms
32,620 KB
testcase_34 AC 174 ms
33,620 KB
testcase_35 AC 242 ms
35,712 KB
testcase_36 AC 231 ms
37,356 KB
testcase_37 AC 228 ms
36,716 KB
testcase_38 AC 246 ms
37,740 KB
testcase_39 AC 258 ms
37,356 KB
testcase_40 AC 285 ms
36,188 KB
testcase_41 AC 295 ms
36,332 KB
testcase_42 AC 248 ms
35,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#ifdef LOCAL
#include "../library/misc/debug.h"
#else 
#define debug(...) 42
#endif // LOCAL

int main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<std::vector<int>> adj(N);
  for (int i = 1; i < N; i++) {
    int u, v; std::cin >> u >> v; u--, v--;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  int M; std::cin >> M;
  std::vector<std::set<int>> S(N);

  std::vector<std::vector<int>> attack(N);
  std::vector<char> exists(N);
  for (int i = 0; i < M; i++) {
    int u; std::cin >> u;
    u--;
    attack[u].push_back(u);
    exists[u] = true;
    for (auto &v : adj[u]) attack[v].push_back(u);
  }

  int tot = 0;
  for (int i = 0; i < N; i++) {
    tot += (!attack[i].empty());
    if (attack[i].size() == 1U) S[attack[i][0]].insert(i);
  }

  debug(attack);
  debug(S);
  for (int i = 0; i < N; i++) {
    int ans = tot;
    if (attack[i].size() != 0U) ans--;
    for (auto &v : adj[i]) {
      if (attack[v].size()) {
        int now = exists[i] + exists[v];
        if (attack[v].size() == now) ans--;
      }

      ans -= static_cast<int>(S[v].size());
      if (S[v].count(i)) ans++;
      if (S[v].count(v)) ans++;
    }

    std::cout << ans << "\n";
  }
}
0