結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 hitonanodehitonanode
提出日時 2023-03-11 10:54:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 4,000 ms
コード長 1,660 bytes
コンパイル時間 6,372 ms
コンパイル使用メモリ 454,296 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 09:46:47
合計ジャッジ時間 7,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /boost_git/boost/unordered/detail/requires_cxx11.hpp:9,
                 from /boost_git/boost/unordered/unordered_set.hpp:17,
                 from /boost_git/boost/unordered_set.hpp:17,
                 from /boost_git/boost/graph/adjacency_list.hpp:20,
                 from main.cpp:6:
/boost_git/boost/config/pragma_message.hpp:24:34: note: '#pragma message: This header is deprecated. Use boost/core/invoke_swap.hpp instead.'
   24 | # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
      |                                  ^~~~~~~
/boost_git/boost/config/header_deprecated.hpp:23:37: note: in expansion of macro 'BOOST_PRAGMA_MESSAGE'
   23 | # define BOOST_HEADER_DEPRECATED(a) BOOST_PRAGMA_MESSAGE("This header is deprecated. Use " a " instead.")
      |                                     ^~~~~~~~~~~~~~~~~~~~
/boost_git/boost/core/swap.hpp:26:1: note: in expansion of macro 'BOOST_HEADER_DEPRECATED'
   26 | BOOST_HEADER_DEPRECATED("boost/core/invoke_swap.hpp")
      | ^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

// 最大重み一般マッチング
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/maximum_weighted_matching.hpp>

using EdgeProperty = boost::property<boost::edge_weight_t, long long, boost::property<boost::edge_index_t, int>>;
using my_graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, EdgeProperty>;

void No() {
    puts("-1");
    exit(0);
}

int main() {
    int N, M;
    cin >> N >> M;
    constexpr int inf = 1 << 20;
    vector dist(N, vector<int>(N, inf));
    for (int i = 0; i < N; ++i) dist.at(i).at(i) = 0;

    while (M--) {
        int a, b;
        cin >> a >> b, --a, --b, dist.at(a).at(b) = dist.at(b).at(a) = 1;
    }

    for (int k = 0; k < N; ++k) for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) dist.at(i).at(j) = min(dist.at(i).at(j), dist.at(i).at(k) + dist.at(k).at(j));
    }

    vector<int> vs;
    for (int i = 0, ci; cin >> ci, i < N; ++i) {
        if (ci) vs.push_back(i);
    }
    const int n_vertices = vs.size();

    if (n_vertices % 2) No();

    my_graph g(n_vertices);
    for (int i = 0; i < n_vertices; ++i) {
        for (int j = 0; j < i; ++j) {
            if (auto w = dist.at(vs.at(i)).at(vs.at(j)); w < inf) add_edge(i, j, EdgeProperty(N - w), g);
        }
    }

    vector<boost::graph_traits<my_graph>::vertex_descriptor> mate1(n_vertices);
    maximum_weighted_matching(g, &mate1[0]);

    auto sz = matching_size(g, &mate1[0]);
    auto ret = matching_weight_sum(g, &mate1[0]);

    if (sz * 2 < n_vertices) No();
    cout << N * vs.size() / 2 - ret << endl;
}
0