結果

問題 No.2286 Join Hands
ユーザー risujirohrisujiroh
提出日時 2023-04-28 22:15:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,608 bytes
コンパイル時間 3,906 ms
コンパイル使用メモリ 259,968 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-11 07:11:00
合計ジャッジ時間 5,796 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,384 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,384 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,384 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 3 ms
4,380 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 5 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if __INCLUDE_LEVEL__

void solve() {
  auto [n, m] = input<int, int>();
  int S = n + n;
  int T = S + 1;
  atcoder::mf_graph<int> g(T + 1);
  while (m--) {
    auto [u, v] = input<int, 2>();
    --u;
    --v;
    assert(u < v);
    g.add_edge(u, n + v, 2);
  }
  for (v : iota(0, n)) {
    g.add_edge(S, v, 2);
    g.add_edge(n + v, T, 2);
  }
  int ans = g.flow(S, T);
  ans -= ans == n - 1;
  ans = ans * 2 - n;
  print(ans);
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

#include <atcoder/maxflow>

namespace std {

template <class T>
auto operator>>(istream& is, T&& t) -> decltype(tuple_cat(t), is) {
  return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

template <class T>
auto operator<<(ostream& os, T&& t) -> decltype(tuple_cat(t), os) {
  auto f = [&os](auto&... xs) -> ostream& {
    [[maybe_unused]] auto sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto&& e : v) {
    is >> e;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  static constexpr auto SEP = is_convertible_v<int, T> ? " " : "\n";
  for (auto sep = ""; const auto& e : v) {
    os << exchange(sep, SEP) << e;
  }
  return os;
}

}  // namespace std

template <class... Ts, class... Args>
auto input(Args&&... args) {
  if constexpr (sizeof...(Ts) == 0) {
    static_assert(sizeof...(Args) == 0);
    return input<int>();
  } else if constexpr (1 < sizeof...(Ts)) {
    static_assert(sizeof...(Args) == 0);
    return input<std::tuple<Ts...>>();
  } else {
    using T = std::tuple_element_t<0, std::tuple<Ts...>>;
    if constexpr (sizeof...(args)) {
      T x(std::forward<Args>(args)...);
      std::cin >> x;
      return x;
    } else {
      T x;
      std::cin >> x;
      return x;
    }
  }
}

template <class T, int N>
std::array<T, N> input() {
  return input<std::array<T, N>>();
}

template <class... Ts>
void print(Ts&&... xs) {
  std::cout << std::tie(xs...) << '\n';
}

using namespace std;

#define show(...) static_cast<void>(0)
#define for(...) for ([[maybe_unused]] auto&& __VA_ARGS__)
#define lambda(...) [&](auto&&... args) { return __VA_ARGS__; }
#define $1 get<0>(tie(args...))
#define $2 get<1>(tie(args...))
#define ALL(f, r, ...) lambda(f(begin($1), end($1), ##__VA_ARGS__))(r)

namespace std::ranges::views {

#include __BASE_FILE__

}  // namespace std::ranges::views

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  views::solve();
}

#endif  // __INCLUDE_LEVEL__
0