結果

問題 No.2618 除霊
ユーザー HaaHaa
提出日時 2024-01-26 22:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 638 ms / 2,000 ms
コード長 1,670 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 174,048 KB
実行使用メモリ 22,164 KB
最終ジャッジ日時 2024-01-26 22:42:42
合計ジャッジ時間 26,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 574 ms
20,116 KB
testcase_07 AC 540 ms
20,084 KB
testcase_08 AC 608 ms
20,844 KB
testcase_09 AC 573 ms
20,728 KB
testcase_10 AC 638 ms
21,592 KB
testcase_11 AC 494 ms
19,860 KB
testcase_12 AC 607 ms
19,732 KB
testcase_13 AC 461 ms
20,452 KB
testcase_14 AC 556 ms
21,820 KB
testcase_15 AC 449 ms
20,100 KB
testcase_16 AC 460 ms
20,056 KB
testcase_17 AC 508 ms
21,424 KB
testcase_18 AC 515 ms
21,336 KB
testcase_19 AC 504 ms
20,680 KB
testcase_20 AC 451 ms
20,264 KB
testcase_21 AC 543 ms
20,544 KB
testcase_22 AC 522 ms
22,164 KB
testcase_23 AC 471 ms
20,648 KB
testcase_24 AC 466 ms
20,328 KB
testcase_25 AC 542 ms
21,344 KB
testcase_26 AC 516 ms
21,268 KB
testcase_27 AC 460 ms
20,252 KB
testcase_28 AC 500 ms
20,716 KB
testcase_29 AC 542 ms
21,444 KB
testcase_30 AC 581 ms
22,072 KB
testcase_31 AC 588 ms
20,140 KB
testcase_32 AC 567 ms
20,268 KB
testcase_33 AC 550 ms
20,524 KB
testcase_34 AC 559 ms
19,940 KB
testcase_35 AC 561 ms
20,404 KB
testcase_36 AC 633 ms
20,908 KB
testcase_37 AC 573 ms
20,644 KB
testcase_38 AC 619 ms
21,292 KB
testcase_39 AC 600 ms
21,420 KB
testcase_40 AC 607 ms
21,200 KB
testcase_41 AC 611 ms
21,676 KB
testcase_42 AC 622 ms
21,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VVI g(n);
    int a, b;
    REP(i,n-1){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int m; cin >> m;
    VI v(m); REP(i,m) cin >> v[i], v[i]--;
    VI p(n,-1);
    REP(i,m) p[v[i]]=i;
    VI f(n,-1);
    REP(i,m){
        if(f[v[i]]==-1)
            f[v[i]]=v[i];
        else if(f[v[i]]>=0)
            f[v[i]]=-2;
        else
            f[v[i]]--;
        for(auto to:g[v[i]]){
            if(f[to]==-1)
                f[to]=v[i];
            else if(f[to]>=0)
                f[to]=-2;
            else
                f[to]--;
        }
    }
    int def=0;
    VI c(n,0);
    REP(i,n){
        if(f[i]!=-1)
            def++;
        if(f[i]>=0)
            c[f[i]]++;
    }
    REP(i,n){
        int ans=def;
        int cnt=0;
        if(p[i]!=-1)
            cnt++;
        ans-=c[i];
        for(auto to:g[i]){
            if(p[to]!=-1)
                cnt++;
            ans-=c[to];
        }
        if(cnt>=2)
            ans--;
        if(p[i]!=-1){
            for(auto to:g[i]){
                if(p[to]!=-1&&f[to]==-2)
                    ans--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0