結果

問題 No.1477 Lamps on Graph
ユーザー y61mpnly61mpnl
提出日時 2021-04-16 22:11:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 205,704 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-09-16 00:56:03
合計ジャッジ時間 6,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 41 ms
6,240 KB
testcase_13 AC 36 ms
6,096 KB
testcase_14 AC 49 ms
6,628 KB
testcase_15 AC 22 ms
4,628 KB
testcase_16 AC 14 ms
5,088 KB
testcase_17 AC 14 ms
4,960 KB
testcase_18 AC 38 ms
7,460 KB
testcase_19 AC 34 ms
6,428 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 33 ms
6,632 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 28 ms
4,964 KB
testcase_24 AC 54 ms
7,084 KB
testcase_25 AC 19 ms
4,548 KB
testcase_26 AC 50 ms
7,536 KB
testcase_27 AC 25 ms
5,012 KB
testcase_28 AC 31 ms
6,048 KB
testcase_29 AC 28 ms
5,480 KB
testcase_30 AC 19 ms
5,392 KB
testcase_31 AC 15 ms
5,136 KB
testcase_32 AC 60 ms
10,220 KB
testcase_33 AC 56 ms
9,232 KB
testcase_34 AC 52 ms
7,396 KB
testcase_35 AC 69 ms
8,892 KB
testcase_36 AC 74 ms
8,948 KB
testcase_37 AC 68 ms
8,896 KB
testcase_38 AC 67 ms
8,896 KB
testcase_39 AC 71 ms
8,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=(b);i<(e);i++)

int main(){
	int n, m;
	scanf("%d %d", &n, &m);

	int a[n], in[n] = {};
	std::vector<int> links[n];
	REP(i, 0, n) scanf("%d", &a[i]);

	REP(i, 0, m){
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		if(a[u]<a[v]){
			links[u].push_back(v);
			in[v]++;
		}else if(a[u]>a[v]){
			links[v].push_back(u);
			in[u]++;
		}
	}

	bool on[n] = {};
	int k;
	scanf("%d", &k);
	REP(i, 0, k){
		int b;
		scanf("%d", &b);
		on[b-1] = true;
	}

	std::queue<int> que;
	REP(i, 0, n) if(in[i]==0) que.push(i);

	std::vector<int> ans;
	while(!que.empty()){
		int from = que.front();
		que.pop();

		if(!on[from]){
			for(int to: links[from]){
				if(--in[to]==0) que.push(to);
			}
		}else{
			on[from] = !on[from];
			ans.push_back(from+1);
			for(int to: links[from]){
				on[to] = !on[to];
				if(--in[to]==0) que.push(to);
			}
		}
	}

	bool ok = true;
	REP(i, 0, n) if(on[i]) ok = false;
	if(!ok) puts("-1");
	else{
		printf("%ld\n", ans.size());
		for(int x: ans) printf("%d\n", x);
	}

	return 0;
}
0