結果

問題 No.1477 Lamps on Graph
ユーザー モグリンモグリン
提出日時 2021-04-16 21:36:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,800 bytes
コンパイル時間 4,677 ms
コンパイル使用メモリ 247,528 KB
実行使用メモリ 12,204 KB
最終ジャッジ日時 2023-09-15 23:47:09
合計ジャッジ時間 8,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 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 38 ms
7,152 KB
testcase_13 AC 34 ms
6,688 KB
testcase_14 AC 46 ms
7,492 KB
testcase_15 AC 22 ms
5,140 KB
testcase_16 AC 13 ms
5,412 KB
testcase_17 AC 13 ms
5,208 KB
testcase_18 AC 34 ms
9,128 KB
testcase_19 AC 31 ms
7,168 KB
testcase_20 AC 14 ms
4,512 KB
testcase_21 AC 30 ms
7,808 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 28 ms
5,428 KB
testcase_24 AC 50 ms
8,288 KB
testcase_25 AC 20 ms
4,848 KB
testcase_26 AC 44 ms
8,728 KB
testcase_27 AC 25 ms
5,552 KB
testcase_28 AC 29 ms
6,816 KB
testcase_29 AC 28 ms
5,824 KB
testcase_30 AC 17 ms
6,180 KB
testcase_31 AC 15 ms
5,652 KB
testcase_32 AC 55 ms
12,204 KB
testcase_33 AC 53 ms
10,896 KB
testcase_34 AC 47 ms
9,180 KB
testcase_35 AC 67 ms
10,488 KB
testcase_36 AC 66 ms
10,416 KB
testcase_37 AC 60 ms
10,280 KB
testcase_38 AC 61 ms
10,428 KB
testcase_39 AC 63 ms
10,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE 
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE 
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>
 
 
using namespace std;
#ifdef ONLINE_JUDGE 
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE 
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
//const ll MOD=1000000007;
const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 


 
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);
 
  ll N,M; cin>>N>>M;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  vector<vector<ll>> graph(N,vector<ll>(0));
  vector<ll> deg(N,0);
  rep(_,M) {
    ll u,v; cin>>u>>v; u--; v--;
    if(A[u]==A[v]) continue;
    if(A[u]>A[v]) swap(u,v);
    graph[u].push_back(v);
    deg[v]++;
  }
  ll K; cin>>K;
  vector<int> lamps(N,0);
  rep(_,K) {
    ll b; cin>>b; b--;
    lamps[b]=1;
  }
  
  vector<ll> anses(0);
  queue<ll> que;
  rep(v,N) if(!deg[v]) que.push(v);
  
  while(!que.empty()) {
    ll v=que.front(); que.pop();
    if(lamps[v]) {
      anses.push_back(v);
      for(auto &nv:graph[v]) lamps[nv]^=1;
    }
    for(auto &nv:graph[v]) {
      deg[nv]--;
      if(!deg[nv]) que.push(nv);
    }
  }
  
  cout<<anses.size()<<'\n';
  for(auto &ans:anses) cout<<ans+1<<'\n';
  return 0;
}
0