結果
| 問題 |
No.3222 Let the World Forget Me
|
| ユーザー |
|
| 提出日時 | 2025-08-01 22:26:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,216 bytes |
| コンパイル時間 | 2,442 ms |
| コンパイル使用メモリ | 214,176 KB |
| 実行使用メモリ | 20,032 KB |
| 最終ジャッジ日時 | 2025-08-01 22:26:48 |
| 合計ジャッジ時間 | 6,484 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<int> P(N);
for(auto &p : P) cin >> p;
vector<set<int>> Graph(N);
for(int i=0; i<N-1; i++){
int u,v; cin >> u >> v;
u--; v--;
Graph.at(u).insert(v);
Graph.at(v).insert(u);
}
vector<bool> NG(N);
vector<int> check(M);
for(auto &c : check) cin >> c,c--,NG.at(c) = true;
priority_queue<pair<long long,int>> Q;
for(int i=0; i<N; i++) if(Graph.at(i).size()) Q.push({P.at(i),i});
long long answer = 0;
while(true){
bool ok = false;
while(Q.size()){
auto [p,pos] = Q.top(); Q.pop();
if(NG.at(pos)) continue;
answer += p;
int to = *Graph.at(pos).begin();
Graph.at(to).erase(pos);
if(Graph.at(to).size() == 1) Q.push({P.at(to),to});
ok = true; break;
}
if(!ok) break;
vector<int> next;
for(auto pos : check) for(auto to : Graph.at(pos)) if(!NG.at(to)) NG.at(to) = true,next.push_back(to);
swap(check,next);
}
cout << answer << endl;
}