結果

問題 No.1477 Lamps on Graph
ユーザー jutama
提出日時 2021-04-16 20:26:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 3,308 ms
コンパイル使用メモリ 168,204 KB
実行使用メモリ 11,828 KB
最終ジャッジ日時 2024-07-02 22:37:20
合計ジャッジ時間 7,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

void input() {
    
    
}


void solve() {
    
    using pii = pair<int, int>;
    
    int N, M; cin >> N >> M;
    vector<pii> A(N), Ar(N);
    vector<vector<int>> edges(N);
    vector<int> B(N);
    
    for(int i = 0; i < N; i++) {
        int a; cin >> a;
        A[i] = {i, a};
        Ar[i] = {a, i};
    }
    sort(Ar.begin(), Ar.end());
    
    for(int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    int K; cin >> K;
    for(int i = 0; i < K; i++) {
        int b; cin >> b;
        b--;
        B[b] = 1;
    }
    
    vector<int> ans;
    for(int i = 0; i < N; i++) {
        int Ai = Ar[i].first;
        int ni = Ar[i].second;
        
        if(B[ni]) {
            ans.push_back(ni);
            
            for(auto e : edges[ni]) {
                if(Ai < A[e].second) {
                    B[e] ^= 1;
                }
            }
        }
    }
    
    int Z = (int)ans.size();
    cout << Z << endl;
    for(int i = 0; i < Z; i++) {
        cout << ans[i]+1 << endl;
    }
    
    
    
    
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    
    input();
    solve();
    
    return 0;
}
0