結果
| 問題 |
No.3024 全単射的
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-14 22:32:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 888 bytes |
| コンパイル時間 | 2,486 ms |
| コンパイル使用メモリ | 209,748 KB |
| 実行使用メモリ | 17,280 KB |
| 最終ジャッジ日時 | 2025-02-14 22:33:11 |
| 合計ジャッジ時間 | 4,389 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int 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,v] : 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";
}