結果

問題 No.3200 Sinking Islands
ユーザー V_Melville
提出日時 2025-07-11 23:11:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 7,282 ms
コンパイル使用メモリ 356,756 KB
実行使用メモリ 17,232 KB
最終ジャッジ日時 2025-07-11 23:12:12
合計ジャッジ時間 16,667 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using P = pair<int, int>;
using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<P> es;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        es.emplace_back(a, b);
    }

    int q;
    cin >> q;
    vector<int> B(q);
    rep(i, q) cin >> B[i], B[i]--;
    
    set<int> st(B.begin(), B.end());
    
    dsu uf(n);
    ll base = (ll)n*(n-1)/2;
    rep(i, m) if (!st.count(i)) {
        auto [a, b] = es[i];
        if (uf.same(a, b)) continue;
        base -= (ll)uf.size(a)*uf.size(b);
        uf.merge(a, b);
    }
    
    vector<ll> ans(q);
    ans[q-1] = base;
    for (int i = q-1; i >= 1; --i) {
        ans[i-1] = ans[i];
        auto [a, b] = es[B[i]];
        if (uf.same(a, b)) continue;
        ans[i-1] -= (ll)uf.size(a)*uf.size(b);
        uf.merge(a, b);
    }
    
    rep(i, q) cout << ans[i] << '\n';
    
    return 0;
}
0