結果
| 問題 |
No.3200 Sinking Islands
|
| コンテスト | |
| ユーザー |
Cafe1942
|
| 提出日時 | 2025-07-11 21:55:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 114 ms / 2,000 ms |
| コード長 | 1,946 bytes |
| コンパイル時間 | 1,376 ms |
| コンパイル使用メモリ | 121,496 KB |
| 実行使用メモリ | 11,620 KB |
| 最終ジャッジ日時 | 2025-07-11 21:56:02 |
| 合計ジャッジ時間 | 5,756 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }
int P[200000];
int S[200000];
void init() {
for (int i = 0;i < 200000;i++) {
P[i] = -1;
S[i] = 1;
}
}
int find(int x) {
if (P[x] == -1) {
return x;
}
else {
P[x] = find(P[x]);
return P[x];
}
}
ll unite(int x, int y) {
int a = find(x);
int b = find(y);
if (a != b) {
P[b] = a;
S[a] += S[b];
return (ll)((ll)(S[a] - S[b]) * (ll)S[b]);
}
return 0;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector < pair<int, pair<int, int>>>V;
for (int i = 0;i < M;i++) {
int A, B;
cin >> A >> B;
A--;
B--;
V.push_back({ (int)1e9,{min(A,B),max(A,B)} });
}
int Q;
cin >> Q;
vector<int>death(Q);
for (int i = 0;i < Q;i++) {
cin >> death[i];
death[i]--;
V[death[i]].first = i;
}
init();
sort(V.begin(), V.end(), greater<pair<int, pair<int, int>>>{});
ll now = 0;
ll maxans = (ll)(N - 1) * (ll)N;
maxans >>= 1;
vector<ll>print;
for (int i = 0;i < V.size();i++) {
if (V[i].first != 1e9) {
print.push_back(maxans - now);
}
now += unite(V[i].second.first, V[i].second.second);
}
reverse(print.begin(), print.end());
for (int i = 0;i < print.size();i++) {
cout << print[i] << "\n";
}
}
Cafe1942