結果
問題 |
No.2618 除霊
|
ユーザー |
![]() |
提出日時 | 2024-01-26 21:51:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 336 ms / 2,000 ms |
コード長 | 1,579 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 195,932 KB |
最終ジャッジ日時 | 2025-02-18 23:11:24 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=1<<30; vector<int> G[MAX]; vector<int> AT[MAX]; int ad[MAX],he[MAX]; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; for(int i=0;i<N-1;i++){ int a,b;cin>>a>>b;a--;b--; G[a].push_back(b); G[b].push_back(a); } int M;cin>>M; for(int i=0;i<M;i++){ int x;cin>>x;x--; for(int to:G[x]){ AT[to].push_back(x); } AT[x].push_back(x); } int ans=0; for(int i=0;i<N;i++) if(si(AT[i])) ans++; for(int i=0;i<N;i++){ if(si(AT[i])==0) continue; if(si(AT[i])==1){ ad[AT[i][0]]++; }else if(si(AT[i])==2){ int x=AT[i][0],y=AT[i][1]; if(x==i||y==i){ he[x]++; he[y]++; }else{ he[i]++; } }else{ he[i]++; } } for(int i=0;i<N;i++){ for(int to:G[i]){ he[to]+=ad[i]; } he[i]+=ad[i]; } for(int i=0;i<N;i++) cout<<ans-he[i]<<"\n"; }