結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー atug tokyoatug tokyo
提出日時 2023-08-12 13:53:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,585 bytes
コンパイル時間 2,668 ms
コンパイル使用メモリ 209,604 KB
実行使用メモリ 14,808 KB
最終ジャッジ日時 2024-04-30 04:24:44
合計ジャッジ時間 4,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 38 ms
12,928 KB
testcase_04 AC 19 ms
12,544 KB
testcase_05 AC 21 ms
6,400 KB
testcase_06 AC 30 ms
12,672 KB
testcase_07 AC 20 ms
5,632 KB
testcase_08 AC 35 ms
14,808 KB
testcase_09 AC 27 ms
7,296 KB
testcase_10 AC 36 ms
11,776 KB
testcase_11 AC 33 ms
11,128 KB
testcase_12 AC 23 ms
9,856 KB
testcase_13 AC 11 ms
5,632 KB
testcase_14 AC 20 ms
7,936 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 30 ms
9,208 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 24 ms
11,008 KB
testcase_19 AC 17 ms
11,648 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 14 ms
6,656 KB
testcase_22 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/dsu>

using namespace std;
using ll = long long;
using ld = long double;

using Pair = pair<int, int>;
using Tuple = tuple<int, int, int>;
using VI1 = vector<int>;
using VI2 = vector<VI1>;
using VL1 = vector<ll>;
using VL2 = vector<VL1>;
using VD1 = vector<ld>;
using VD2 = vector<VD1>;
using VB1 = vector<bool>;
using VB2 = vector<VB1>;
using VP1 = vector<Pair>;
using VP2 = vector<VP1>;
using VT1 = vector<Tuple>;
using VT2 = vector<VT1>;

using Queue = queue<int>;
using DQ = deque<int>;
using PQ = priority_queue<int, vector<int>, greater<int>>;
using Table = VI2;
using Graph = VI2;
using DSU = atcoder::dsu;

/** io */
template <typename T>
std::vector<T> input_vec(int N);
template <typename T>
void output_row(std::vector<T> &row);
template <typename T>
void output_col(std::vector<T> &col);
void outputYesNo(bool yes, const string &Yes = "Yes", const string &No = "No");
/** minmax */
template <typename T>
bool chmin(T &a, T b);
template <typename T>
bool chmax(T &a, T b);

auto solve() {
  int N, M;
  cin >> N >> M;
  auto N2 = N * 2;
  DSU ds(N2);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ds.merge(a, b);
  }
  int cnt = 0;
  auto groups = ds.groups();
  for (auto &g : groups) {
    cnt += g.size() % 2;
  }
  assert(cnt % 2 == 0);
  cnt /= 2;
  return cnt;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--) {
    auto result = solve();
    cout << result << '\n';
    // output_row(result);
    // output_col(result);
    // outputYesNo(result, "Yes", "No");
  }
}

/** @note 使用頻度が高く毎回貼付するのが面倒なライブラリを実装しておく。*/

template <typename T>
std::vector<T> input_vec(int N) {
  std::vector<T> v(N);
  for (auto &vi : v) {
    cin >> vi;
  }
  return v;
}

void outputYesNo(bool yes, const string &Yes, const string &No) {
  if (yes)
    cout << Yes << '\n';
  else
    cout << No << '\n';
}

template <typename T>
void output_row(std::vector<T> &row) {
  int N = row.size();
  for (int i = 0; i < N; ++i) {
    if (i > 0) cout << ' ';
    cout << row.at(i);
  }
  cout << '\n';
}

template <typename T>
void output_col(std::vector<T> &col) {
  int N = col.size();
  for (int i = 0; i < N; ++i) {
    cout << col.at(i) << '\n';
  }
}

template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
0