結果

問題 No.1477 Lamps on Graph
ユーザー ebi_flyebi_fly
提出日時 2021-04-16 21:26:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 3,981 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 140,788 KB
実行使用メモリ 10,868 KB
最終ジャッジ日時 2023-09-15 23:29:15
合計ジャッジ時間 6,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 71 ms
6,724 KB
testcase_13 AC 74 ms
6,356 KB
testcase_14 AC 86 ms
7,168 KB
testcase_15 AC 32 ms
4,924 KB
testcase_16 AC 25 ms
4,936 KB
testcase_17 AC 29 ms
4,892 KB
testcase_18 AC 124 ms
7,668 KB
testcase_19 AC 72 ms
6,768 KB
testcase_20 AC 23 ms
4,376 KB
testcase_21 AC 108 ms
6,748 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 40 ms
5,052 KB
testcase_24 AC 110 ms
7,816 KB
testcase_25 AC 31 ms
4,620 KB
testcase_26 AC 110 ms
8,228 KB
testcase_27 AC 37 ms
5,100 KB
testcase_28 AC 49 ms
6,348 KB
testcase_29 AC 51 ms
5,312 KB
testcase_30 AC 72 ms
5,228 KB
testcase_31 AC 41 ms
5,032 KB
testcase_32 AC 183 ms
10,620 KB
testcase_33 AC 141 ms
10,616 KB
testcase_34 AC 173 ms
10,868 KB
testcase_35 AC 151 ms
10,080 KB
testcase_36 AC 146 ms
10,208 KB
testcase_37 AC 107 ms
10,224 KB
testcase_38 AC 126 ms
10,080 KB
testcase_39 AC 142 ms
10,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include <chrono>
#include <random>
#include <memory>

/* template */
 
using size_t = std::size_t;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;
using pii = std::pair<int,int>;
using pll = std::pair<i64,i64>;
template<class T> using vec = std::vector<T>;
template<class T> using pq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#ifdef LOCAL
#define debug(...)                                                    \
  std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
      debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
 
void debug_out() { std::cerr << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
  std::cerr << " " << h;
  if (sizeof...(t) > 0) std::cout << " :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (i64 i = (i64)(a); i< (i64)(n); i++)
#define RRep(i, a, n) for (i64 i = ((i64)(n-i64(1))); i>=(i64)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template<class T> void fill(std::vector<T> &v) { for(T &e: v) std::cin >> e; }

namespace ebi {

template<class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost) { }
};

template<class T>
using Graph = std::vector<std::vector<Edge<T>>>;

using graph = std::vector<std::vector<int>>;

}

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/std::gcd(a,b);
}

template<class T>
T Pow(T x, i64 n){
    T res = 1;
    while(n>0){
        if(n&1) res = res *x;
        x = x*x;
        n>>=1;
    }
    return res;
}
 
constexpr i64 LNF = std::numeric_limits<i64>::max()/4;

constexpr int INF = std::numeric_limits<int>::max()/4;

const long double PI=acos(-1);

const std::vector<int> dy =  {1,0,-1,0,1,1,-1,-1};
const std::vector<int> dx = {0,1,0,-1,1,-1,1,-1};

/* template */

int main(){
    std::cout << std::fixed << std::setprecision(15);
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m;
    std::cin >> n >> m;
    std::vector<int> a(n);
    std::vector<int> idx(n);
    rep(i,0,n) {
        std::cin >> a[i];
        idx[i] = i;
    }
    std::sort(all(idx), [&](int i, int j) { return a[i] < a[j]; });
    ebi::graph g(n);
    rep(i,0,m) {
        int u,v;
        std::cin >> u >> v;
        u--; v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    int k;
    std::cin >> k;
    std::vector<int> seen(n, -1);
    rep(i,0,k) {
        int b;
        std::cin >> b;
        b--;
        seen[b] = 1;
    }
    std::vector<int> ans;
    rep(i,0,n) {
        int v = idx[i];
        if(seen[v] < 0) continue;
        ans.emplace_back(v+1);
        for(auto nv: g[v]) {
            if(a[nv] <= a[v]) continue;
            seen[nv] *= -1;
        }
    }
    std::cout << ans.size() << std::endl;
    for(auto val: ans) {
        std::cout << val << std::endl;
    }
}
0