結果
| 問題 | No.3781 Erase One, Gain from the Other |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-21 05:16:02 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 82 ms / 2,000 ms |
| + 769µs | |
| コード長 | 687 bytes |
| 記録 | |
| コンパイル時間 | 1,611 ms |
| コンパイル使用メモリ | 201,772 KB |
| 実行使用メモリ | 11,400 KB |
| 最終ジャッジ日時 | 2026-10-30 20:55:17 |
| 合計ジャッジ時間 | 8,271 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 34 |
ソースコード
#include <iostream>
#include <ranges>
#include <algorithm>
#include <vector>
#include <atcoder/dsu>
using namespace std;
using ll=long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int ttt;
cin>>ttt;
while(ttt--){
int n,m;
cin>>n>>m;
vector<int> a(n);
vector<array<int,3>> edges;
ll ans=0;
for(int i=0;i<n;i++){
cin>>a[i];
edges.push_back({a[i],n,i});
ans-=a[i];
}
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
u--;v--;
edges.push_back({a[u]+a[v],u,v});
}
ranges::sort(edges,greater{});
atcoder::dsu uf(n+1);
for(auto[w,u,v]:edges){
if(!uf.same(u,v)){
ans+=w;
uf.merge(u,v);
}
}
cout<<ans<<endl;
}
}