結果

問題 No.1477 Lamps on Graph
ユーザー norikamenorikame
提出日時 2021-04-16 22:13:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 2,535 ms
コンパイル使用メモリ 213,712 KB
実行使用メモリ 20,884 KB
最終ジャッジ日時 2023-09-16 00:59:23
合計ジャッジ時間 11,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 145 ms
11,496 KB
testcase_13 AC 149 ms
11,052 KB
testcase_14 AC 181 ms
12,524 KB
testcase_15 AC 66 ms
6,568 KB
testcase_16 AC 58 ms
8,504 KB
testcase_17 AC 61 ms
8,156 KB
testcase_18 AC 246 ms
16,840 KB
testcase_19 AC 151 ms
12,496 KB
testcase_20 AC 45 ms
5,356 KB
testcase_21 AC 205 ms
14,436 KB
testcase_22 AC 24 ms
4,472 KB
testcase_23 AC 84 ms
7,024 KB
testcase_24 AC 228 ms
14,476 KB
testcase_25 AC 60 ms
6,112 KB
testcase_26 AC 233 ms
16,200 KB
testcase_27 AC 82 ms
7,672 KB
testcase_28 AC 112 ms
11,032 KB
testcase_29 AC 104 ms
8,720 KB
testcase_30 AC 125 ms
10,260 KB
testcase_31 AC 80 ms
8,648 KB
testcase_32 AC 356 ms
20,884 KB
testcase_33 AC 318 ms
20,716 KB
testcase_34 AC 242 ms
10,800 KB
testcase_35 AC 322 ms
20,440 KB
testcase_36 AC 314 ms
20,440 KB
testcase_37 AC 263 ms
20,208 KB
testcase_38 AC 286 ms
20,444 KB
testcase_39 AC 317 ms
20,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

int main() {
	int n, m, k;
	cin >> n >> m;
	vector<int> a(n);
	map<int, vector<int>> aval;
	rep(i, n) {
		cin >> a[i];
		aval[a[i]].push_back(i);
	}
	vector<vector<int>> g(n);
	rep(i, m) {
		int ui, vi;
		cin >> ui >> vi;
		--ui; --vi;
		g[ui].push_back(vi);
		g[vi].push_back(ui);
	}
	cin >> k;
	vector<bool> sw(n);
	rep(i, k) {
		int bi;
		cin >> bi;
		--bi;
		sw[bi] = true;
	}
	vector<int> res;
	for (auto p : aval) {
		rep(i, (int)(p.second.size())) {
			if (sw[p.second[i]]) {
				res.push_back(p.second[i]+1);
				sw[p.second[i]] = false;
				rep(j, (int)(g[p.second[i]].size())) if (a[g[p.second[i]][j]] > a[p.second[i]]) {
					sw[g[p.second[i]][j]] = (!sw[g[p.second[i]][j]]);
				}
			}
		}
	}
	bool ok = true;
	rep(i, n) if (sw[i]) ok = false;
	if (ok) {
		cout << (int)(res.size()) << endl;
		rep(i, (int)(res.size())) cout << res[i] << endl;
	}
	else cout << -1 << endl;
	return 0;
}
0