結果

問題 No.1477 Lamps on Graph
ユーザー se1ka2se1ka2
提出日時 2021-04-16 20:16:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 79,260 KB
実行使用メモリ 13,016 KB
最終ジャッジ日時 2023-09-15 20:40:26
合計ジャッジ時間 9,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
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 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 93 ms
6,584 KB
testcase_31 WA -
testcase_32 AC 252 ms
13,008 KB
testcase_33 AC 205 ms
12,828 KB
testcase_34 AC 243 ms
9,436 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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), r(n);
    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);
            r.add_edge(v, u);
        }
        if(a[u] > a[v]){
            g.add_edge(v, u);
            r.add_edge(u, v);
        }
    }
    int k;
    cin >> k;
    bool b[100005]{0};
    for(int i = 0; i < k; i++){
        int u;
        cin >> u;
        u--;
        b[u] = true;
    }
    bool c[100005]{0};
    queue<int> que;
    for(int u = 0; u < n; u++){
        if(r.g[u].size() == 0){
            c[u] = true;
            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];
            if(!c[v]){
                c[v] = true;
                que.push(v);
            }
        }
    }
    cout << (int)ans.size() << endl;
    for(int u : ans) cout << u + 1 << endl;
    cout << endl;
}
0