結果

問題 No.1477 Lamps on Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-22 09:22:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 122,296 KB
実行使用メモリ 13,744 KB
最終ジャッジ日時 2024-04-24 15:01:30
合計ジャッジ時間 8,318 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 109 ms
8,140 KB
testcase_13 AC 122 ms
8,176 KB
testcase_14 AC 136 ms
9,048 KB
testcase_15 AC 55 ms
5,760 KB
testcase_16 AC 36 ms
5,376 KB
testcase_17 AC 39 ms
5,376 KB
testcase_18 AC 158 ms
9,856 KB
testcase_19 AC 104 ms
7,788 KB
testcase_20 AC 37 ms
5,376 KB
testcase_21 AC 141 ms
8,592 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 69 ms
6,656 KB
testcase_24 AC 166 ms
10,052 KB
testcase_25 AC 51 ms
5,504 KB
testcase_26 AC 154 ms
9,628 KB
testcase_27 AC 62 ms
6,400 KB
testcase_28 AC 73 ms
6,912 KB
testcase_29 AC 80 ms
6,904 KB
testcase_30 AC 88 ms
6,504 KB
testcase_31 AC 53 ms
5,588 KB
testcase_32 AC 264 ms
13,740 KB
testcase_33 AC 224 ms
12,976 KB
testcase_34 AC 243 ms
13,744 KB
testcase_35 AC 218 ms
12,416 KB
testcase_36 AC 204 ms
12,040 KB
testcase_37 AC 158 ms
11,136 KB
testcase_38 AC 174 ms
11,396 KB
testcase_39 AC 245 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
 
int main(){
 
    long long N, M, A, B, C, start, K;
    long long from, alt, d;
    cin >> N >> M;
    pq<pair<long long, long long>> que;
    vector<long long> num(N), ans;
    deque<bool> color(N);
    for (int i=0; i<N; i++) cin >> num[i];
    vector<vector<long long>> E(N);
 
    for (int i=0; i < M; i++){
        cin >> A >> B;
        A--; B--;
        E[A].push_back(B);
        E[B].push_back(A);
    }

    cin >> K;
    for (int i=0; i<K; i++){
        cin >> B; B--;
        color[B] = 1;
        que.push({num[B], B});
    }
 
    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (color[from] == 0) continue;
        color[from] = 0;
        ans.push_back(from+1);
        for (auto to : E[from]){
            if (num[to] > num[from]){
                color[to] ^= 1;
                if (color[to] == 1){
                    que.push({num[to], to});
                }
            }
        }
    }

    cout << ans.size() << endl;
    for (auto x : ans) cout << x << endl;
 
    return 0;
}
0