結果

問題 No.1477 Lamps on Graph
ユーザー 👑 jupirojupiro
提出日時 2021-04-16 22:01:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,802 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 126,188 KB
実行使用メモリ 11,252 KB
最終ジャッジ日時 2023-09-16 00:41:21
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 43 ms
6,864 KB
testcase_13 AC 40 ms
6,540 KB
testcase_14 AC 52 ms
7,416 KB
testcase_15 AC 24 ms
4,816 KB
testcase_16 AC 16 ms
5,244 KB
testcase_17 AC 15 ms
4,828 KB
testcase_18 AC 41 ms
7,988 KB
testcase_19 AC 37 ms
7,036 KB
testcase_20 AC 15 ms
4,384 KB
testcase_21 AC 35 ms
7,124 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 30 ms
5,348 KB
testcase_24 AC 60 ms
8,136 KB
testcase_25 AC 21 ms
4,792 KB
testcase_26 AC 56 ms
8,476 KB
testcase_27 AC 27 ms
5,380 KB
testcase_28 AC 33 ms
6,476 KB
testcase_29 AC 33 ms
5,688 KB
testcase_30 AC 21 ms
5,352 KB
testcase_31 AC 17 ms
5,324 KB
testcase_32 AC 66 ms
11,040 KB
testcase_33 AC 62 ms
11,252 KB
testcase_34 AC 57 ms
11,072 KB
testcase_35 AC 79 ms
10,476 KB
testcase_36 AC 79 ms
10,476 KB
testcase_37 AC 66 ms
10,736 KB
testcase_38 AC 69 ms
10,604 KB
testcase_39 AC 73 ms
10,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <array>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

void solve()
{
  int n, m; cin >> n >> m;
  std::vector<std::pair<int , int>> vp(n);
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> vp[i].first;
    a[i] = vp[i].first;
    vp[i].second = i;
  }
  std::sort(vp.begin(), vp.end());
  std::vector<std::vector<int>> g(n);
  for (int i = 0; i < m; ++i)
  {
    int u, v; cin >> u >> v;
    u -= 1, v -= 1;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  int k; cin >> k;
  std::vector<int> on(n);
  for (int i = 0; i < k; ++i)
  {
    int b; cin >> b;
    b -= 1;
    on[b] = 1;
  }
  std::vector<int> res;
  for(const auto [_, idx] : vp)
  {
    if(on[idx])
    {
      res.emplace_back(idx);
      for(const auto nxt : g[idx])
      {
        if(a[idx] < a[nxt])
        {
          on[nxt] ^= 1;
        }
      }
      on[idx] ^= 1;
    }
  }
  for (int i = 0; i < n; ++i)
  {
    if(on[i])
    {
      cout << -1 << "\n";
      return;
    }
  }
  cout << res.size() << "\n";
  for (int i = 0; i < (int)res.size(); ++i)
  {
    cout << res[i] + 1 << "\n";
  }
}
int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int kkt = 1;
  //cin >> kkt;
  while(kkt--)
    solve();
  return 0;
}
0