結果
| 問題 | 
                            No.1477 Lamps on Graph
                             | 
                    
| コンテスト | |
| ユーザー | 
                             PCTprobability
                         | 
                    
| 提出日時 | 2021-04-01 23:31:11 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 76 ms / 2,000 ms | 
| コード長 | 2,602 bytes | 
| コンパイル時間 | 4,356 ms | 
| コンパイル使用メモリ | 259,012 KB | 
| 最終ジャッジ日時 | 2025-01-20 07:24:26 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 38 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define all(s) (s).begin(),(s).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
//#define P pair<ll,ll>
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
void gbjsmzmfuuvdf(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}
vector<ll> graph[200000];
ll f[200000];
int main() {
  gbjsmzmfuuvdf();
  ll n,m;
  cin>>n>>m;
  vector<ll> ans;
  vector<ll> a(n);
  vcin(a);
  for(int i=0;i<m;i++){
    ll x,y;
    cin>>x>>y;
    x--;
    y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  vector<pair<ll,ll>> s;
  for(int i=0;i<n;i++){
    s.push_back({a[i],i});
  }
  sor(s);
  ll k;
  cin>>k;
  for(int i=0;i<k;i++){
    ll b;
    cin>>b;
    b--;
    f[b]=1;
  }
  ll count=0;
  for(int i=0;i<n;i++){
    ll g=s[i].se;
    if(f[g]==1){
      count++;
      ans.push_back(g+1);
      for(int j=0;j<graph[g].size();j++){
        if(a[g]<a[graph[g][j]]){
          f[graph[g][j]]=1-f[graph[g][j]];
        }
      }
    }
  }
  cout<<count<<endl;
  for(int i=0;i<count;i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}
            
            
            
        
            
PCTprobability