結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー kekenxkekenx
提出日時 2023-08-12 22:04:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 207,228 KB
実行使用メモリ 12,480 KB
最終ジャッジ日時 2024-04-30 17:07:28
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 74 ms
12,480 KB
testcase_04 AC 12 ms
8,192 KB
testcase_05 AC 50 ms
8,448 KB
testcase_06 AC 46 ms
10,884 KB
testcase_07 AC 55 ms
8,320 KB
testcase_08 AC 47 ms
11,996 KB
testcase_09 AC 63 ms
9,984 KB
testcase_10 AC 75 ms
11,916 KB
testcase_11 AC 59 ms
11,116 KB
testcase_12 AC 46 ms
9,216 KB
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 43 ms
8,064 KB
testcase_15 AC 43 ms
6,940 KB
testcase_16 AC 89 ms
11,392 KB
testcase_17 AC 22 ms
6,944 KB
testcase_18 AC 40 ms
9,532 KB
testcase_19 AC 8 ms
7,592 KB
testcase_20 AC 48 ms
6,944 KB
testcase_21 AC 26 ms
6,944 KB
testcase_22 AC 30 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> g(2 * n);

  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<int> group(2 * n, -1);

  function<void(int, int)> dfs = [&g, &group, &dfs](int cur, int root) {
    for (int next : g[cur]) {
      if (group[next] == -1) {
	group[next] = root;
	dfs(next, root);
      }
    }
  };

  for (int i = 0; i < 2 * n; i++) {
    if (group[i] == -1) {
      group[i] = i;
      dfs(i, i);
    }
  }

  vector<int> count(2 * n, 0);
  for (int i = 0; i < 2 * n; i++) {
    count[group[i]]++;
  }
  int n_odds = 0;
  for (const int &c : count) {
    if (c & 1)
      n_odds++;
  }

  cout << n_odds / 2 << '\n';
  return 0;
}

0