結果

問題 No.1477 Lamps on Graph
ユーザー seiyu_kyoproseiyu_kyopro
提出日時 2021-10-21 02:50:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 2,766 bytes
コンパイル時間 3,611 ms
コンパイル使用メモリ 196,624 KB
実行使用メモリ 17,508 KB
最終ジャッジ日時 2023-10-20 11:16:25
合計ジャッジ時間 12,267 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 159 ms
8,988 KB
testcase_13 AC 135 ms
8,956 KB
testcase_14 AC 192 ms
9,656 KB
testcase_15 AC 84 ms
5,716 KB
testcase_16 AC 52 ms
6,812 KB
testcase_17 AC 47 ms
6,688 KB
testcase_18 AC 126 ms
13,040 KB
testcase_19 AC 124 ms
9,808 KB
testcase_20 AC 51 ms
5,084 KB
testcase_21 AC 106 ms
11,560 KB
testcase_22 AC 35 ms
4,372 KB
testcase_23 AC 109 ms
6,044 KB
testcase_24 AC 215 ms
11,076 KB
testcase_25 AC 73 ms
5,524 KB
testcase_26 AC 188 ms
12,468 KB
testcase_27 AC 98 ms
6,444 KB
testcase_28 AC 120 ms
8,448 KB
testcase_29 AC 105 ms
7,128 KB
testcase_30 AC 57 ms
8,484 KB
testcase_31 AC 50 ms
7,112 KB
testcase_32 AC 192 ms
17,508 KB
testcase_33 AC 193 ms
15,396 KB
testcase_34 AC 178 ms
14,340 KB
testcase_35 AC 276 ms
15,132 KB
testcase_36 AC 269 ms
14,868 KB
testcase_37 AC 256 ms
14,340 KB
testcase_38 AC 247 ms
14,604 KB
testcase_39 AC 253 ms
14,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
#include <climits>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

vector<vector<int>> edge;
vector<int> state;

void solve(int now) {
    state[now] ^= 1;
    for(auto i : edge[now]) state[i] ^= 1;
}

int main() {
    int n, m;
    cin >> n >> m;

    state.resize(n);
    edge.resize(n);

    map<int,int> mii;
    vector<pair<int,int>> v;

    rep(i, n) {
        int a;
        cin >> a;
        mii[i] = a;
        v.emplace_back(a, i);
    }

    rep(i, m) {
        int j, k;
        cin >> j >> k;
        j--;
        k--;
        if(mii[j] < mii[k]) edge[j].push_back(k);
        if(mii[k] < mii[j]) edge[k].push_back(j);
    }

    int k;
    cin >> k;

    rep(i, k) {
        int b;
        cin >> b;
        b--;
        state[b] = 1;
    }

    sort(all(v));

    vector<int> ans;

    for(auto [i, j] : v) {
        // cout << "state : " << state << endl;
        if(state[j]) {
            solve(j);
            ans.push_back(j + 1);
        }
    }

    // cout << "ans" << endl;
    auto sum = accumulate(all(state), 0);
    if(sum == 0) {
        cout << int(ans.size()) << endl;
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}
0