結果

問題 No.1477 Lamps on Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-22 09:23:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 122,028 KB
実行使用メモリ 81,992 KB
最終ジャッジ日時 2024-04-24 15:01:47
合計ジャッジ時間 9,924 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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();
        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