結果

問題 No.1477 Lamps on Graph
ユーザー y61mpnly61mpnl
提出日時 2021-04-16 21:47:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 204,852 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-09-16 00:07:43
合計ジャッジ時間 6,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 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 40 ms
6,484 KB
testcase_13 AC 36 ms
6,360 KB
testcase_14 AC 46 ms
6,712 KB
testcase_15 AC 21 ms
4,844 KB
testcase_16 AC 14 ms
5,136 KB
testcase_17 AC 13 ms
5,000 KB
testcase_18 AC 37 ms
7,308 KB
testcase_19 AC 33 ms
6,460 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 31 ms
6,680 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 27 ms
4,972 KB
testcase_24 AC 55 ms
7,256 KB
testcase_25 AC 19 ms
4,552 KB
testcase_26 AC 48 ms
7,572 KB
testcase_27 AC 25 ms
5,364 KB
testcase_28 AC 30 ms
6,292 KB
testcase_29 AC 28 ms
5,392 KB
testcase_30 AC 18 ms
5,404 KB
testcase_31 AC 15 ms
5,224 KB
testcase_32 AC 59 ms
10,224 KB
testcase_33 AC 55 ms
9,404 KB
testcase_34 WA -
testcase_35 AC 70 ms
8,996 KB
testcase_36 AC 69 ms
8,944 KB
testcase_37 AC 62 ms
8,940 KB
testcase_38 AC 64 ms
8,892 KB
testcase_39 AC 70 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];
	REP(i, 0, n) scanf("%d", &a[i]);

	int in[n] = {};
	std::vector<int> links[n];
	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{
			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] ^= 1;
			ans.push_back(from+1);
			for(int to: links[from]){
				on[to] ^= 1;
				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