結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー kisakisa
提出日時 2023-08-12 14:45:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 178,204 KB
実行使用メモリ 11,128 KB
最終ジャッジ日時 2024-04-30 07:07:22
合計ジャッジ時間 4,139 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 93 ms
11,128 KB
testcase_04 AC 14 ms
7,168 KB
testcase_05 AC 64 ms
7,424 KB
testcase_06 AC 61 ms
9,600 KB
testcase_07 AC 67 ms
7,168 KB
testcase_08 AC 60 ms
10,572 KB
testcase_09 AC 84 ms
8,576 KB
testcase_10 AC 93 ms
10,668 KB
testcase_11 AC 78 ms
9,836 KB
testcase_12 AC 53 ms
8,320 KB
testcase_13 AC 26 ms
6,940 KB
testcase_14 AC 49 ms
7,168 KB
testcase_15 AC 46 ms
6,940 KB
testcase_16 AC 102 ms
9,984 KB
testcase_17 AC 24 ms
6,940 KB
testcase_18 AC 46 ms
8,448 KB
testcase_19 AC 9 ms
6,944 KB
testcase_20 AC 50 ms
6,940 KB
testcase_21 AC 29 ms
6,944 KB
testcase_22 AC 32 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<vector<int>> A;
vector<bool> V;

int dfs(int u) {
  if(V[u]) {
    return 0;
}    
    V[u] = true;
  int size = 1;
  for(auto v : A[u]) {
    size += dfs(v);
  }
  return size;
}

int main() {
  int n, m;
  cin >> n >> m;
  A.resize(2*n);
  V.resize(2*n, false);
  for(int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--; 
    A[a].push_back(b);
    A[b].push_back(a);
  }
  int p = 0;
  for (int i=0; i<2*n; i++) {
    if(!V[i]) {
      int size = dfs(i);
      if(size%2!=0) {
        p++;
      }  
    }
  }
  cout << p/2 << endl;
}
0