結果
| 問題 | No.2418 情報通だよ!Nafmoくん | 
| コンテスト | |
| ユーザー |  keisuke6 | 
| 提出日時 | 2023-08-12 14:29:39 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 76 ms / 2,000 ms | 
| コード長 | 386 bytes | 
| コンパイル時間 | 4,259 ms | 
| コンパイル使用メモリ | 253,428 KB | 
| 最終ジャッジ日時 | 2025-02-16 04:55:33 | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define int long long
signed main(){
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>> S(M);
  dsu uf(2*N);
  for(int i=0;i<M;i++){
  	int a,b;cin>>a>>b;
  	a--;
  	b--;
  	uf.merge(a,b);
  }
  int ans = N;
  for(int i=0;i<2*N;i++)if(uf.leader(i) == i) ans -= uf.size(i)/2;
  cout<<ans<<endl;
}
            
            
            
        