結果
問題 |
No.3024 全単射的
|
ユーザー |
|
提出日時 | 2025-02-14 22:11:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 962 bytes |
コンパイル時間 | 4,708 ms |
コンパイル使用メモリ | 260,236 KB |
実行使用メモリ | 9,984 KB |
最終ジャッジ日時 | 2025-02-14 22:12:17 |
合計ジャッジ時間 | 5,530 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 4 |
ソースコード
#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<ll,ll>> edge(n); vector<ll> ca; ca.reserve(2 * n); for(auto &&[u, v] : edge){ cin >> u >> v; ca.emplace_back(u); ca.emplace_back(v); } sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); vector<int> cnt(ca.size()); atcoder::dsu uf(ca.size()); for(auto &&[u, v] : edge){ u = lower_bound(ca.begin(), ca.end(), u) - ca.begin(); v = lower_bound(ca.begin(), ca.end(), v) - ca.begin(); uf.merge(u, v); cnt[u]++; } int ans = 0; auto G = uf.groups(); for(auto &&vec : G){ int tot = 0; for(auto &&v : vec){ tot += cnt[v]; } ans += min((int)vec.size(), tot); } cout << ans << '\n'; }