結果

問題 No.1477 Lamps on Graph
ユーザー KKT89
提出日時 2021-04-16 21:15:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 4,834 ms
コンパイル使用メモリ 219,964 KB
最終ジャッジ日時 2025-01-20 19:23:17
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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