結果
問題 | No.3024 全単射的 |
ユーザー |
|
提出日時 | 2025-02-14 22:44:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 449 ms / 5,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 2,224 ms |
コンパイル使用メモリ | 208,932 KB |
実行使用メモリ | 34,816 KB |
最終ジャッジ日時 | 2025-02-14 22:44:26 |
合計ジャッジ時間 | 5,613 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){ios_base::sync_with_stdio(false);cin.tie(nullptr);long long N,M; cin >> N >> M;map<long long,vector<long long>> Graph;while(N--){long long x,y; cin >> x >> y;Graph[x].push_back(y);Graph[y].push_back(x);}set<long long> already;int answer = 0;for(auto &[k,ign] : Graph){if(already.count(k)) continue;already.insert(k);int edge = 0,ver = 0;queue<long long> Q; Q.push(k);while(Q.size()){auto pos = Q.front(); Q.pop();ver++;for(auto &to : Graph[pos]){edge++;if(already.count(to)) continue;already.insert(to); Q.push(to);}}edge /= 2;answer += min(ver,edge);}cout << answer << "\n";}