結果

問題 No.1477 Lamps on Graph
ユーザー kimiyukikimiyuki
提出日時 2021-04-16 22:27:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 210,332 KB
実行使用メモリ 11,372 KB
最終ジャッジ日時 2023-09-16 01:20:13
合計ジャッジ時間 5,920 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 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 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 37 ms
6,668 KB
testcase_13 AC 34 ms
6,400 KB
testcase_14 AC 44 ms
7,372 KB
testcase_15 AC 21 ms
4,824 KB
testcase_16 AC 15 ms
4,836 KB
testcase_17 AC 14 ms
4,636 KB
testcase_18 AC 40 ms
7,696 KB
testcase_19 AC 33 ms
6,696 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 34 ms
6,792 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 26 ms
5,164 KB
testcase_24 AC 50 ms
8,008 KB
testcase_25 AC 18 ms
4,556 KB
testcase_26 AC 47 ms
8,100 KB
testcase_27 AC 24 ms
5,164 KB
testcase_28 AC 28 ms
6,220 KB
testcase_29 AC 27 ms
5,680 KB
testcase_30 AC 21 ms
5,376 KB
testcase_31 AC 16 ms
4,976 KB
testcase_32 AC 65 ms
11,372 KB
testcase_33 AC 61 ms
10,336 KB
testcase_34 AC 45 ms
8,360 KB
testcase_35 AC 65 ms
10,048 KB
testcase_36 AC 65 ms
10,124 KB
testcase_37 AC 58 ms
9,616 KB
testcase_38 AC 63 ms
9,756 KB
testcase_39 AC 64 ms
9,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

vector<int> solve(int n, int m, const vector<int64_t>& a, const vector<int>& u, const vector<int>& v, int k, const vector<int>& b) {
    vector<vector<int> > g(n);
    REP (i, m) {
        if (a[u[i]] < a[v[i]]) g[u[i]].push_back(v[i]);
        if (a[v[i]] < a[u[i]]) g[v[i]].push_back(u[i]);
    }
    vector<int> order(n);
    iota(ALL(order), 0);
    sort(ALL(order), [&](int x, int y) { return a[x] < a[y]; });
    vector<bool> used(n);
    for (int b_i : b) {
        used[b_i] = true;
    }
    vector<int> ans;
    for (int x : order) {
        if (used[x]) {
            ans.push_back(x);
            for (int y : g[x]) {
                used[y] = not used[y];
            }
        }
    }
    return ans;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N, M;
    cin >> N;
    cin >> M;
    vector<int64_t> A(N);
    REP (i, N) { cin >> A[i]; }
    vector<int> u(M), v(M);
    REP (i, M) { cin >> u[i] >> v[i]; -- u[i]; -- v[i]; }
    int K;
    cin >> K;
    vector<int> B(K);
    REP (i, K) { cin >> B[i]; -- B[i]; }
    auto ans = solve(N, M, A, u, v, K, B);
    cout << ans.size() << endl;
    REP (i, ans.size()) { cout << ans[i] + 1 << endl; }
    return 0;
}
0