- 题解
- ABC302E 孤立
ABC302E. 孤立
- @ 2026-9-5 21:32:39
太轻松了吧?
正常模拟即可。
当然,你会用二分的对吧。
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T = 1;
const int N = 3e5 + 10;
int n, q, cnt;
vector<set<int>> graph(N);
void Solve() {
cin >> n >> q;
cnt = n;
while (q--) {
int op;
cin >> op;
if (op == 1) {
int u, v;
cin >> u >> v;
if (graph[u].size() == 0) cnt--;
if (graph[v].size() == 0) cnt--;
graph[u].insert(v);
graph[v].insert(u);
} else {
int u;
cin >> u;
if (graph[u].size() > 0) cnt++;
for (auto v : graph[u]) {
auto del = graph[v].lower_bound(u);
graph[v].erase(del);
if (graph[v].size() == 0) cnt++;
}
graph[u].clear();
}
cout << cnt << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while (T--) {
Solve();
}
return 0;
}
0 条评论
目前还没有评论...