結果

問題 No.1477 Lamps on Graph
ユーザー KKT89KKT89
提出日時 2021-04-16 21:15:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 2,777 ms
コンパイル使用メモリ 217,116 KB
実行使用メモリ 11,000 KB
最終ジャッジ日時 2023-09-15 23:10:29
合計ジャッジ時間 7,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 47 ms
6,744 KB
testcase_13 AC 43 ms
6,476 KB
testcase_14 AC 57 ms
7,316 KB
testcase_15 AC 24 ms
4,928 KB
testcase_16 AC 17 ms
5,104 KB
testcase_17 AC 16 ms
4,948 KB
testcase_18 AC 44 ms
7,668 KB
testcase_19 AC 38 ms
6,904 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 37 ms
6,860 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 30 ms
5,212 KB
testcase_24 AC 67 ms
7,944 KB
testcase_25 AC 21 ms
4,708 KB
testcase_26 AC 57 ms
8,304 KB
testcase_27 AC 28 ms
5,196 KB
testcase_28 AC 37 ms
6,368 KB
testcase_29 AC 32 ms
5,476 KB
testcase_30 AC 21 ms
5,260 KB
testcase_31 AC 19 ms
5,272 KB
testcase_32 AC 66 ms
11,000 KB
testcase_33 AC 64 ms
10,848 KB
testcase_34 AC 54 ms
10,664 KB
testcase_35 AC 89 ms
10,328 KB
testcase_36 AC 86 ms
10,120 KB
testcase_37 AC 75 ms
10,280 KB
testcase_38 AC 81 ms
10,128 KB
testcase_39 AC 85 ms
10,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<vector<int>> g(n);
    vector<int> b(n);
    for(int i=0;i<m;i++){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cin >> m;
    while(m--){
        int x; cin >> x;
        x--;
        b[x]++;
    }
    vector<int> v(n);
    for(int i=0;i<n;i++){
        v[i]=i;
    }
    sort(v.begin(), v.end(),[&](auto i,auto j){
        return a[i]<a[j];
    });
    vector<int> res;
    for(int i=0;i<n;i++){
        int j=v[i];
        if(b[j]==0)continue;
        res.push_back(j+1);
        b[j]=0;
        for(int t:g[j]){
            if(a[j]<a[t])b[t]^=1;
        }
    }
    cout << res.size() << "\n";
    for(int i:res){
        cout << i << "\n";
    }
}
0