結果

問題 No.1477 Lamps on Graph
ユーザー firiexpfiriexp
提出日時 2021-04-16 20:41:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 2,587 ms
コンパイル使用メモリ 110,044 KB
実行使用メモリ 10,564 KB
最終ジャッジ日時 2023-09-15 21:43:51
合計ジャッジ時間 4,963 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 38 ms
6,108 KB
testcase_13 AC 36 ms
6,100 KB
testcase_14 AC 46 ms
6,596 KB
testcase_15 AC 22 ms
4,500 KB
testcase_16 AC 14 ms
4,984 KB
testcase_17 AC 14 ms
4,856 KB
testcase_18 AC 37 ms
7,732 KB
testcase_19 AC 32 ms
6,408 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 32 ms
6,804 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 28 ms
4,764 KB
testcase_24 AC 52 ms
7,336 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 48 ms
7,644 KB
testcase_27 AC 26 ms
5,028 KB
testcase_28 AC 30 ms
5,992 KB
testcase_29 AC 29 ms
5,232 KB
testcase_30 AC 19 ms
5,428 KB
testcase_31 AC 16 ms
5,060 KB
testcase_32 AC 61 ms
10,564 KB
testcase_33 AC 57 ms
9,688 KB
testcase_34 AC 53 ms
7,720 KB
testcase_35 AC 72 ms
9,100 KB
testcase_36 AC 69 ms
9,232 KB
testcase_37 AC 60 ms
9,052 KB
testcase_38 AC 65 ms
9,108 KB
testcase_39 AC 68 ms
9,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for (auto &&i : A) scanf("%d", &i);
    vector<vector<int>> G(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        if(A[u] < A[v]) G[u].emplace_back(v);
        if(A[v] < A[u]) G[v].emplace_back(u);
    }
    vector<int> on(n);
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        int x;
        scanf("%d", &x);
        on[x-1]++;
    }
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        for (auto &&j : G[i]) {
            d[j]++;
        }
    }
    queue<int> Q;
    for (int i = 0; i < n; ++i) {
        if(!d[i]) Q.emplace(i);
    }
    vector<int> ans;
    while(!Q.empty()){
        int x = Q.front(); Q.pop();
        int ok = on[x];
        if(on[x]) on[x] = 0, ans.emplace_back(x);
        for (auto &&y : G[x]) {
            if(ok) on[y] ^= 1;
            if(!(--d[y])) Q.emplace(y);
        }
    }
    cout << ans.size() << "\n";
    for (auto &&i : ans) {
        cout << i+1 << "\n";
    }
    return 0;
}
0