結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 hitonanodehitonanode
提出日時 2023-03-11 10:47:08
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,805 bytes
コンパイル時間 9,114 ms
コンパイル使用メモリ 459,232 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 09:46:22
合計ジャッジ時間 18,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1 ms
4,348 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,348 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,348 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 2 ms
4,348 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 2 ms
4,348 KB
testcase_47 RE -
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 RE -
testcase_52 RE -
testcase_53 AC 2 ms
4,348 KB
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:13:
/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 <algorithm>
#include <iostream>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

using namespace boost;

typedef property<edge_weight_t, float, property<edge_index_t, int>> EdgeProperty;
typedef adjacency_list<vecS, vecS, undirectedS, no_property, EdgeProperty> my_graph;

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();

    graph_traits<my_graph>::vertex_iterator vi, vi_end;
    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);
        }
    }

    graph_traits<my_graph>::vertex_descriptor mate1(n_vertices);
    maximum_weighted_matching(g, &mate1);

    auto sz = matching_size(g, &mate1);
    int ret = matching_weight_sum(g, &mate1);
    if (sz * 2 < n_vertices) No();
    ret = N * vs.size() / 2 - ret;
    cout << ret << endl;
}
0