結果

問題 No.1477 Lamps on Graph
ユーザー startcppstartcpp
提出日時 2021-04-16 20:18:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 980 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 11,240 KB
最終ジャッジ日時 2023-09-15 20:43:20
合計ジャッジ時間 7,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,712 KB
testcase_01 AC 3 ms
5,900 KB
testcase_02 AC 3 ms
5,904 KB
testcase_03 AC 3 ms
5,776 KB
testcase_04 AC 3 ms
5,704 KB
testcase_05 AC 3 ms
5,756 KB
testcase_06 AC 3 ms
5,764 KB
testcase_07 AC 3 ms
5,704 KB
testcase_08 AC 3 ms
5,760 KB
testcase_09 AC 3 ms
5,972 KB
testcase_10 AC 3 ms
5,760 KB
testcase_11 AC 3 ms
5,692 KB
testcase_12 AC 112 ms
8,020 KB
testcase_13 AC 116 ms
7,756 KB
testcase_14 AC 135 ms
8,416 KB
testcase_15 AC 56 ms
7,132 KB
testcase_16 AC 42 ms
6,920 KB
testcase_17 AC 44 ms
6,600 KB
testcase_18 AC 168 ms
8,132 KB
testcase_19 AC 109 ms
7,940 KB
testcase_20 AC 41 ms
6,608 KB
testcase_21 AC 148 ms
7,768 KB
testcase_22 AC 25 ms
6,456 KB
testcase_23 AC 72 ms
7,304 KB
testcase_24 AC 166 ms
8,924 KB
testcase_25 AC 53 ms
6,868 KB
testcase_26 AC 159 ms
8,836 KB
testcase_27 AC 65 ms
7,316 KB
testcase_28 AC 82 ms
7,724 KB
testcase_29 AC 82 ms
7,548 KB
testcase_30 AC 95 ms
6,660 KB
testcase_31 AC 60 ms
6,836 KB
testcase_32 AC 263 ms
11,012 KB
testcase_33 AC 217 ms
10,816 KB
testcase_34 AC 252 ms
11,240 KB
testcase_35 AC 218 ms
10,468 KB
testcase_36 AC 212 ms
10,392 KB
testcase_37 AC 164 ms
10,276 KB
testcase_38 AC 182 ms
10,384 KB
testcase_39 AC 220 ms
10,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//小さな数から操作して、大きな数を後に回せば、全部消灯させることができる。
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n, m;
int a[100000];
vector<int> et[100000];
bool on[100000];

signed main() {
	int i, j;
	
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) {
		int u, v;
		 cin >> u >> v; u--; v--;
		 et[u].push_back(v);
		 et[v].push_back(u);
	}
	
	int K; cin >> K;
	rep(i, K) { int b; cin >> b; b--; on[b] = true; }
	
	vector<P> vec;
	rep(i, n) { vec.push_back(P(a[i], i)); }
	sort(vec.begin(), vec.end());
	
	vector<int> ans;
	rep(i, n) {
		int id = vec[i].second;
		if (on[id] == false) continue;
		ans.push_back(id);
		on[id] = false;
		rep(j, et[id].size()) {
			int v = et[id][j];
			if (a[v] > a[id]) on[v] = !on[v];
		}
	}
	
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i] + 1 << endl;
	}
	return 0;
}
0