結果
| 問題 | No.2618 除霊 |
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2024-01-26 22:42:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 528 ms / 2,000 ms |
| コード長 | 1,670 bytes |
| 記録 | |
| コンパイル時間 | 1,641 ms |
| コンパイル使用メモリ | 173,140 KB |
| 実行使用メモリ | 21,912 KB |
| 最終ジャッジ日時 | 2024-09-28 08:38:48 |
| 合計ジャッジ時間 | 22,777 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 43 |
ソースコード
#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;
}
Haa