結果
| 問題 | No.3222 Let the World Forget Me |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-01 22:46:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,625 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 181,032 KB |
| 実行使用メモリ | 9,728 KB |
| 最終ジャッジ日時 | 2025-08-01 22:46:37 |
| 合計ジャッジ時間 | 8,386 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 3 TLE * 1 -- * 23 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:43:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
43 | auto [v, i] = *st.rbegin();
| ^
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;
void solve(){
int n, m; cin >> n >> m;
vector<int> p(n); for(int i=0; i<n; i++) cin >> p[i];
vector<vector<int>> T(n);
for(int i=0; i<n-1; i++){
int u, v; cin >> u >> v;
u--; v--;
T[u].push_back(v);
T[v].push_back(u);
}
vector<bool> used(n, false);
set<int> que;
set<pair<int, int>> st; for(int i=0; i<n; i++) if((int)T[i].size() == 1) st.insert({p[i], i});
for(int i=0; i<m; i++){
int c; cin >> c;
c--;
used[c] = true;
que.insert(c);
st.erase({p[c], c});
}
ll ans = 0LL;
for(int t=1; ; t++){
if(st.empty()) break;
auto [v, i] = *st.rbegin();
ans += v;
used[i] = true;
que.erase(i);
st.erase({v, i});
set<int> nxt;
for(auto v : que){
for(int u : T[v]){
if(used[u]) continue;
used[u] = true;
nxt.insert(u);
st.erase({p[u], u});
}
}
}
cout << ans << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T=1;
//cin >> T;
while(T--) solve();
}