結果

問題 No.1477 Lamps on Graph
ユーザー MisterMister
提出日時 2021-04-16 21:05:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 10,648 KB
最終ジャッジ日時 2023-09-15 22:40:55
合計ジャッジ時間 4,962 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 40 ms
6,612 KB
testcase_13 AC 37 ms
6,240 KB
testcase_14 AC 50 ms
6,992 KB
testcase_15 AC 23 ms
4,872 KB
testcase_16 AC 16 ms
4,952 KB
testcase_17 AC 15 ms
4,568 KB
testcase_18 AC 41 ms
7,292 KB
testcase_19 AC 34 ms
6,556 KB
testcase_20 AC 15 ms
4,384 KB
testcase_21 AC 35 ms
6,576 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 29 ms
5,208 KB
testcase_24 AC 55 ms
7,540 KB
testcase_25 AC 20 ms
4,660 KB
testcase_26 AC 50 ms
7,908 KB
testcase_27 AC 27 ms
5,136 KB
testcase_28 AC 32 ms
6,160 KB
testcase_29 AC 31 ms
5,376 KB
testcase_30 AC 21 ms
5,084 KB
testcase_31 AC 17 ms
5,076 KB
testcase_32 AC 68 ms
10,648 KB
testcase_33 AC 64 ms
10,368 KB
testcase_34 AC 54 ms
10,628 KB
testcase_35 AC 75 ms
9,844 KB
testcase_36 AC 73 ms
9,752 KB
testcase_37 AC 72 ms
9,748 KB
testcase_38 AC 75 ms
9,872 KB
testcase_39 AC 75 ms
9,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> xs(n);
    for (auto& x : xs) cin >> x;

    vector<vector<int>> graph(n);
    while (m--) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<bool> stat(n, false);
    {
        int k;
        cin >> k;
        while (k--) {
            int v;
            cin >> v;
            stat[--v] = true;
        }
    }

    vector<int> vs(n);
    iota(vs.begin(), vs.end(), 0);
    sort(vs.begin(), vs.end(),
         [&](int u, int v) { return xs[u] < xs[v]; });

    vector<int> ans;
    for (auto v : vs) {
        if (!stat[v]) continue;
        ans.push_back(v + 1);

        stat[v] = !stat[v];
        for (auto u : graph[v]) {
            if (xs[u] > xs[v]) stat[u] = !stat[u];
        }
    }

    cout << ans.size() << "\n";
    for (auto v : ans) cout << v << "\n";
}

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

    solve();

    return 0;
}
0