結果
| 問題 |
No.2618 除霊
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-30 10:54:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,588 bytes |
| コンパイル時間 | 2,585 ms |
| コンパイル使用メモリ | 217,888 KB |
| 最終ジャッジ日時 | 2025-02-19 00:46:02 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 39 |
ソースコード
#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";
}
}
}