結果

問題 No.3200 Sinking Islands
ユーザー t98slider
提出日時 2025-07-11 21:52:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 4,463 ms
コンパイル使用メモリ 255,940 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-07-11 21:53:17
合計ジャッジ時間 8,644 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> edge(m);
    for(auto &&[x, y] : edge){
        cin >> x >> y;
        x--, y--;
    }
    atcoder::dsu uf(n);
    int Q;
    cin >> Q;
    vector<int> b(Q);
    vector<ll> ans(Q);
    vector<bool> used(m);
    for(auto &&ei : b){
        cin >> ei;
        ei--;
        used[ei] = true;
    }
    ll cur = 0;
    for(int i = 0; i < m; i++){
        if(used[i]) continue;
        auto [u, v] = edge[i];
        if(uf.same(u, v)) continue;
        ll A = uf.size(u), B = uf.size(v);
        uf.merge(u, v);
        cur += A * B;
    }
    ll r = n * (ll)(n - 1) / 2;
    ans[Q - 1] = cur;
    for(int i = Q - 2; i >= 0; i--){
        auto [u, v] = edge[b[i + 1]];
        if(!uf.same(u, v)) cur += (ll)(uf.size(u)) * uf.size(v);
        uf.merge(u, v);
        ans[i] = cur;
    }
    //for(auto v : ans) cout << v << '\n';
    for(auto v : ans) cout << r - v << '\n';
}
0