結果
問題 | No.2618 除霊 |
ユーザー |
![]() |
提出日時 | 2024-01-26 22:15:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 2,207 bytes |
コンパイル時間 | 3,373 ms |
コンパイル使用メモリ | 257,596 KB |
実行使用メモリ | 27,720 KB |
最終ジャッジ日時 | 2024-09-28 08:20:10 |
合計ジャッジ時間 | 11,817 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>namespace zawa {using i16 = std::int16_t;using i32 = std::int32_t;using i64 = std::int64_t;using i128 = __int128_t;using u8 = std::uint8_t;using u16 = std::uint16_t;using u32 = std::uint32_t;using u64 = std::uint64_t;using usize = std::size_t;} // namespace zawanamespace zawa {void SetFastIO() {std::cin.tie(nullptr)->sync_with_stdio(false);}void SetPrecision(u32 dig) {std::cout << std::fixed << std::setprecision(dig);}} // namespace zawausing namespace zawa;int main() {SetFastIO();int n; std::cin >> n;std::vector g(n, std::vector<int>{});for (int _{} ; _ < n - 1 ; _++) {int a, b; std::cin >> a >> b;a--; b--;g[a].emplace_back(b);g[b].emplace_back(a);}std::vector<int> pos(n, -1);int m; std::cin >> m;std::vector<int> ghost(m);for (int i{} ; auto& gh : ghost) {std::cin >> gh;gh--;pos[gh] = i;i++;}std::vector<int> count(n);for (int i{} ; i < n ; i++) if (pos[i] != -1) {count[i]++;for (auto x : g[i]) {count[x]++;}}std::vector unique(m, std::vector<int>{});for (int i{} ; i < n ; i++) if (pos[i] != -1) {int gh{pos[i]};if (count[i] == 1) unique[gh].push_back(i);for (auto x : g[i]) {if (count[x] == 1) unique[gh].push_back(x);}}// for (auto x : count) std::cerr << x << ' ';// std::cerr << std::endl;int all{(int)std::ranges::count_if(count, [](const auto& i) -> bool { return i > 0; })};for (int v{} ; v < n ; v++) {int ans{all};if (pos[v] != -1) ans -= unique[pos[v]].size();for (auto x : g[v]) if (pos[x] != -1) ans -= unique[pos[x]].size();if (count[v] > 1) {ans--;}if (pos[v] != -1) {// std::cerr << v << " hello" << std::endl;for (auto x : g[v]) {// std::cerr << "travase " << x << std::endl;if (pos[x] == -1) continue;if (count[x] == 2) ans--;}}std::cout << ans << '\n';}}