結果

問題 No.2618 除霊
ユーザー KKT89KKT89
提出日時 2024-01-30 10:54:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,588 bytes
コンパイル時間 3,899 ms
コンパイル使用メモリ 219,980 KB
実行使用メモリ 17,480 KB
最終ジャッジ日時 2024-01-30 10:54:44
合計ジャッジ時間 17,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,676 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 205 ms
16,624 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 185 ms
17,236 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 204 ms
16,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    vector<int> deg(n), cnt(n), cnt2(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x -= 1, y -= 1;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int m;
    cin >> m;
    vector<bool> f(n);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        a -= 1;
        f[a] = true;
        for (int b : g[a]) {
            deg[b] += 1;
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += (deg[i] >= 1 or f[i]);
        for (int t : g[i]) {
            cnt[i] += (deg[t] == 1);
            cnt2[i] += (deg[t] == 1 and !f[t]);
        }
    }
    for (int i = 0; i < n; i++) {
        int res = sum;
        if (deg[i] >= 1 or f[i]) res -= 1;

        if (f[i]) {
            res -= cnt[i];
            for (int t : g[i]) {
                if (f[t]) {
                    res -= cnt2[t];
                }
            }
            cout << res << "\n";
        } else {
            for (int t : g[i]) {
                if (f[t]) {
                    res -= cnt2[t] + (deg[t] == 0);
                }
                if (deg[i] == 1) res += 1;
            }
            cout << res << "\n";
        }
    }
}
0