結果

問題 No.1477 Lamps on Graph
ユーザー norikamenorikame
提出日時 2021-04-16 22:07:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,258 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 213,676 KB
実行使用メモリ 814,704 KB
最終ジャッジ日時 2023-09-16 00:49:00
合計ジャッジ時間 4,739 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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, vector<int>(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