結果

問題 No.1477 Lamps on Graph
ユーザー Plan8Plan8
提出日時 2021-04-16 23:07:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 207,584 KB
実行使用メモリ 10,512 KB
最終ジャッジ日時 2023-09-16 02:30:12
合計ジャッジ時間 5,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 35 ms
6,212 KB
testcase_13 AC 32 ms
6,004 KB
testcase_14 AC 42 ms
6,488 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 12 ms
4,832 KB
testcase_17 AC 12 ms
4,576 KB
testcase_18 AC 33 ms
7,636 KB
testcase_19 AC 29 ms
6,420 KB
testcase_20 AC 13 ms
4,376 KB
testcase_21 AC 29 ms
6,680 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 25 ms
4,876 KB
testcase_24 AC 49 ms
7,200 KB
testcase_25 AC 18 ms
4,380 KB
testcase_26 AC 43 ms
7,632 KB
testcase_27 AC 23 ms
4,960 KB
testcase_28 AC 28 ms
5,936 KB
testcase_29 AC 27 ms
5,100 KB
testcase_30 AC 17 ms
5,488 KB
testcase_31 AC 14 ms
4,984 KB
testcase_32 AC 53 ms
10,512 KB
testcase_33 AC 49 ms
9,448 KB
testcase_34 AC 46 ms
7,708 KB
testcase_35 AC 63 ms
9,064 KB
testcase_36 AC 61 ms
9,104 KB
testcase_37 AC 54 ms
8,992 KB
testcase_38 AC 52 ms
9,088 KB
testcase_39 AC 62 ms
9,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

void Main(){
    int N,M,K;
    cin >> N >> M;
    VI A(N),light(N,0),deg(N,0);
    VVI edge(N);
    REP(i,N) cin >> A[i];
    while(M--){
        int u,v; cin >> u >> v; u--; v--;

        if(A[u]<A[v]) edge[u].push_back(v), deg[v]++;
        if(A[u]>A[v]) edge[v].push_back(u), deg[u]++;
    }

    cin >> K;
    while(K--){
        int b; cin >> b; b--;
        light[b] = 1;
    }

    int Z = 0;
    VI ans;
    stack<int> stk; REP(i,N) if(deg[i]==0) stk.push(i);
    while(!stk.empty()){
        int v = stk.top(); stk.pop();

        if(light[v]){
            Z++;
            ans.push_back(v+1);
            for(int to : edge[v]){
                light[to] = 1-light[to];
            }
        }

        for(int to : edge[v]){
            deg[to]--;
            if(deg[to] == 0) stk.push(to);
        }
    }

    cout << Z << en;
    for(int v : ans) cout << v << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    while(t--) Main();
    return 0;
}
0