結果

問題 No.1477 Lamps on Graph
ユーザー モグリン
提出日時 2021-04-16 21:36:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,800 bytes
コンパイル時間 4,840 ms
コンパイル使用メモリ 249,452 KB
実行使用メモリ 12,508 KB
最終ジャッジ日時 2024-07-03 01:00:24
合計ジャッジ時間 8,826 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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