結果

問題 No.1477 Lamps on Graph
ユーザー akaneakane
提出日時 2021-04-16 20:55:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 209,524 KB
実行使用メモリ 11,348 KB
最終ジャッジ日時 2023-09-15 22:17:42
合計ジャッジ時間 8,166 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 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,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 70 ms
6,716 KB
testcase_13 AC 78 ms
6,680 KB
testcase_14 AC 86 ms
7,304 KB
testcase_15 AC 32 ms
4,636 KB
testcase_16 AC 22 ms
5,140 KB
testcase_17 AC 28 ms
4,928 KB
testcase_18 AC 131 ms
8,140 KB
testcase_19 AC 72 ms
6,744 KB
testcase_20 AC 26 ms
4,568 KB
testcase_21 AC 113 ms
7,056 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 43 ms
5,180 KB
testcase_24 AC 113 ms
8,280 KB
testcase_25 AC 34 ms
4,708 KB
testcase_26 AC 112 ms
8,348 KB
testcase_27 AC 36 ms
5,124 KB
testcase_28 AC 46 ms
6,308 KB
testcase_29 AC 54 ms
5,720 KB
testcase_30 AC 76 ms
5,376 KB
testcase_31 AC 41 ms
5,060 KB
testcase_32 AC 212 ms
11,348 KB
testcase_33 AC 162 ms
10,904 KB
testcase_34 AC 194 ms
11,240 KB
testcase_35 AC 151 ms
10,356 KB
testcase_36 AC 142 ms
10,240 KB
testcase_37 AC 94 ms
9,908 KB
testcase_38 AC 114 ms
10,368 KB
testcase_39 AC 142 ms
10,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;
    vector<int> A(N+1,0);
    vector<int> light(N+1,0);
    rep(i,N){
        int a;
        cin>>a; A[i+1] = -a;
    }
    vector<vector<int>> load(N+1,vector<int>());
    rep(i,M){
        int u,v; cin>>u>>v;
        load[u].push_back(v);
        load[v].push_back(u);
    }

    priority_queue<pair<int,int>> que; //強さ・番号
    int K; cin>>K;
    rep(i,K){
        int B; cin>>B;
        light[B]=1;
        que.push(make_pair(A[B],B));
    }

    vector<int> ans;
    while(que.size()){
        auto x = que.top(); que.pop();
        int a = x.first, b=x.second;
        if(light[b]==0) continue;
        light[b]=0;
        // cerr << a << " " << b  <<endl;
        ans.push_back(b);
        for(int s:load[b]){
            if(A[s]<a){
                light[s] = (light[s]+1)%2;
            }
            if(light[s]){
                que.push(make_pair(A[s],s));
            }
        }
    }

    cout << ans.size() << endl;
    for(int x:ans){
        cout << x << endl;
    }

}
0