結果

問題 No.1477 Lamps on Graph
ユーザー se1ka2se1ka2
提出日時 2021-04-16 20:23:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 79,748 KB
実行使用メモリ 10,364 KB
最終ジャッジ日時 2023-09-15 21:02:56
合計ジャッジ時間 7,275 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 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,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 112 ms
6,268 KB
testcase_13 AC 114 ms
5,996 KB
testcase_14 AC 132 ms
6,880 KB
testcase_15 AC 56 ms
4,688 KB
testcase_16 AC 38 ms
4,948 KB
testcase_17 AC 41 ms
5,172 KB
testcase_18 AC 161 ms
7,400 KB
testcase_19 AC 105 ms
6,372 KB
testcase_20 AC 39 ms
4,696 KB
testcase_21 AC 143 ms
6,612 KB
testcase_22 AC 23 ms
4,436 KB
testcase_23 AC 70 ms
5,304 KB
testcase_24 AC 168 ms
7,452 KB
testcase_25 AC 51 ms
4,768 KB
testcase_26 AC 158 ms
7,488 KB
testcase_27 AC 61 ms
5,276 KB
testcase_28 AC 80 ms
6,092 KB
testcase_29 AC 82 ms
5,468 KB
testcase_30 AC 93 ms
5,760 KB
testcase_31 AC 59 ms
5,304 KB
testcase_32 AC 251 ms
10,364 KB
testcase_33 AC 204 ms
9,196 KB
testcase_34 AC 245 ms
7,436 KB
testcase_35 AC 212 ms
8,804 KB
testcase_36 AC 210 ms
8,720 KB
testcase_37 AC 162 ms
8,824 KB
testcase_38 AC 187 ms
8,660 KB
testcase_39 AC 206 ms
8,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
using namespace std;

struct Graph
{
    int n;
    std::vector<std::vector<int>> g;
    
    Graph(){}
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    int a[100005];
    for(int i = 0; i < n; i++) cin >> a[i];
    Graph g(n);
    int d[100005]{0};
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        if(a[u] < a[v]){
            g.add_edge(u, v);
            d[v]++;
        }
        if(a[u] > a[v]){
            g.add_edge(v, u);
            d[u]++;
        }
    }
    int k;
    cin >> k;
    bool b[100005]{0};
    for(int i = 0; i < k; i++){
        int u;
        cin >> u;
        u--;
        b[u] = true;
    }
    queue<int> que;
    for(int u = 0; u < n; u++){
        if(!d[u]) que.push(u);
    }
    vector<int> ans;
    while(que.size()){
        int u = que.front();
        que.pop();
        if(b[u]) ans.push_back(u);
        for(int v : g.g[u]){
            if(b[u]) b[v] = !b[v];
            d[v]--;
            if(!d[v]) que.push(v);
        }
    }
    cout << (int)ans.size() << endl;
    for(int u : ans) cout << u + 1 << endl;
    cout << endl;
}
0