結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー Nzt3Nzt3
提出日時 2023-08-12 19:32:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 210,772 KB
実行使用メモリ 11,152 KB
最終ジャッジ日時 2024-04-30 14:38:05
合計ジャッジ時間 4,135 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 55 ms
11,152 KB
testcase_04 AC 15 ms
7,108 KB
testcase_05 AC 32 ms
6,948 KB
testcase_06 AC 40 ms
9,564 KB
testcase_07 AC 30 ms
6,940 KB
testcase_08 AC 39 ms
10,532 KB
testcase_09 AC 41 ms
8,064 KB
testcase_10 AC 51 ms
10,672 KB
testcase_11 AC 50 ms
9,852 KB
testcase_12 AC 32 ms
8,320 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 27 ms
7,296 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 50 ms
9,436 KB
testcase_17 AC 12 ms
6,944 KB
testcase_18 AC 30 ms
8,576 KB
testcase_19 AC 12 ms
6,944 KB
testcase_20 AC 21 ms
6,940 KB
testcase_21 AC 18 ms
6,944 KB
testcase_22 AC 15 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector G(N*2,vector(0,0));
  for(int i=0;i<M;i++){
    int A,B;
    cin>>A>>B;
    --A,--B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  vector<bool>v(N*2);
  int ans=0;
  for(int i=0;i<N*2;i++){
    if(v[i])continue;
    queue<int>bfs;
    bfs.push(i);
    v[i]=true;
    int s=0;
    while(bfs.size()){
      int c=bfs.front();
      ++s;
      bfs.pop();
      for(int j:G[c]){
        if(!v[j]){
          v[j]=true;
          bfs.push(j);
        }
      }
    }
    ans+=s%2;
  }
  cout<<ans/2<<'\n';
}
0