結果

問題 No.2618 除霊
ユーザー 👑 emthrmemthrm
提出日時 2024-01-26 22:47:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 3,601 ms
コンパイル使用メモリ 262,132 KB
実行使用メモリ 62,736 KB
最終ジャッジ日時 2024-01-26 22:48:10
合計ジャッジ時間 19,257 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 2 ms
6,676 KB
testcase_06 AC 310 ms
37,268 KB
testcase_07 AC 312 ms
37,084 KB
testcase_08 AC 365 ms
47,140 KB
testcase_09 AC 418 ms
53,476 KB
testcase_10 AC 508 ms
61,676 KB
testcase_11 AC 205 ms
31,528 KB
testcase_12 AC 363 ms
47,124 KB
testcase_13 AC 300 ms
44,160 KB
testcase_14 AC 347 ms
62,220 KB
testcase_15 AC 121 ms
25,608 KB
testcase_16 AC 131 ms
26,324 KB
testcase_17 AC 218 ms
44,876 KB
testcase_18 AC 310 ms
60,064 KB
testcase_19 AC 141 ms
27,596 KB
testcase_20 AC 123 ms
25,836 KB
testcase_21 AC 213 ms
42,808 KB
testcase_22 AC 290 ms
62,736 KB
testcase_23 AC 305 ms
44,480 KB
testcase_24 AC 276 ms
43,768 KB
testcase_25 AC 336 ms
53,528 KB
testcase_26 AC 348 ms
60,020 KB
testcase_27 AC 269 ms
43,616 KB
testcase_28 AC 275 ms
44,760 KB
testcase_29 AC 334 ms
53,528 KB
testcase_30 AC 380 ms
62,164 KB
testcase_31 AC 362 ms
47,448 KB
testcase_32 AC 169 ms
26,044 KB
testcase_33 AC 233 ms
31,292 KB
testcase_34 AC 294 ms
34,672 KB
testcase_35 AC 309 ms
39,468 KB
testcase_36 AC 351 ms
44,336 KB
testcase_37 AC 391 ms
46,428 KB
testcase_38 AC 410 ms
50,940 KB
testcase_39 AC 434 ms
54,028 KB
testcase_40 AC 465 ms
56,068 KB
testcase_41 AC 466 ms
59,964 KB
testcase_42 AC 526 ms
61,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<vector<int>> graph(n);
  REP(_, n - 1) {
    int a, b; cin >> a >> b; --a; --b;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }
  int m; cin >> m;
  vector<int> ghost(n, -1), treated(n, false);
  vector<set<int>> inv(n);
  REP(i, m) {
    int v; cin >> v; --v;
    ghost[v] = i;
    treated[v] = true;
    inv[v].emplace(i);
    for (const int e : graph[v]) {
      treated[e] = true;
      inv[e].emplace(i);
    }
  }
  vector<set<int>> under(m);
  REP(i, n) {
    if (inv[i].size() == 1) under[*inv[i].begin()].emplace(i);
  }
  const int night = ranges::count(treated, true);
  REP(v, n) {
    int ans = night;
    if (treated[v]) --ans;
    for (const int adj : graph[v]) {
      if (!treated[adj]) continue;
      if (ghost[adj] != -1) {  // 外にいたずらしない
        ans -= under[ghost[adj]].size();
        if (under[ghost[adj]].contains(adj)) ++ans;
        if (under[ghost[adj]].contains(v)) ++ans;
      }
      if (inv[adj].empty() ||
          (inv[adj].size() == 1 && (inv[adj].contains(ghost[v]) || inv[adj].contains(ghost[adj]))) ||
          (inv[adj].size() == 2 && inv[adj].contains(ghost[v]) && inv[adj].contains(ghost[adj]))) {
        --ans;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
0