結果

問題 No.1477 Lamps on Graph
ユーザー hamihami
提出日時 2021-12-07 10:18:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 177,396 KB
実行使用メモリ 10,888 KB
最終ジャッジ日時 2023-09-21 16:41:23
合計ジャッジ時間 7,900 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 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,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 107 ms
6,756 KB
testcase_13 AC 110 ms
6,352 KB
testcase_14 AC 130 ms
7,248 KB
testcase_15 AC 54 ms
4,580 KB
testcase_16 AC 38 ms
4,880 KB
testcase_17 AC 43 ms
4,900 KB
testcase_18 AC 170 ms
7,940 KB
testcase_19 AC 105 ms
6,808 KB
testcase_20 AC 39 ms
4,380 KB
testcase_21 AC 144 ms
6,832 KB
testcase_22 AC 23 ms
4,376 KB
testcase_23 AC 70 ms
5,136 KB
testcase_24 AC 161 ms
7,900 KB
testcase_25 AC 51 ms
4,552 KB
testcase_26 AC 156 ms
8,136 KB
testcase_27 AC 62 ms
5,136 KB
testcase_28 AC 79 ms
6,304 KB
testcase_29 AC 81 ms
5,556 KB
testcase_30 AC 95 ms
5,216 KB
testcase_31 AC 56 ms
5,088 KB
testcase_32 AC 257 ms
10,888 KB
testcase_33 AC 211 ms
10,816 KB
testcase_34 AC 246 ms
10,816 KB
testcase_35 AC 211 ms
10,172 KB
testcase_36 AC 204 ms
10,108 KB
testcase_37 AC 158 ms
9,964 KB
testcase_38 AC 173 ms
10,096 KB
testcase_39 AC 207 ms
10,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
using LL = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); ++i)
template<class T>void chmin(T&a, T b){if(a > b) a = b;}
template<class T>void chmax(T&a, T b){if(a < b) a = b;}


int main(){
	int N, M; cin >> N >> M;
	vector<P> A(N);
	vector<int> points(N);
	for(int i = 0; i < N; ++i){
		int tmp; cin >> tmp;
		points[i] = tmp;
		A[i] = make_pair(tmp, i);
	}
	sort(A.begin(), A.end());
	Graph G(N);
	for(int i = 0; i < M; ++i){
		int u, v; cin >> u >> v;
		--u; --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<bool> state(N, false);
	int K; cin >> K;
	for(int i = 0; i < K; ++i){
		int tmp; cin >> tmp; state[tmp-1] = true;
	}
	vector<int> ans;
	for(int i = 0; i < N; ++i){
		int now_point = A[i].first;
		int now_num = A[i].second;
		if(state[now_num]){
			ans.push_back(now_num);
			state[now_num] = false;
			for(auto next_num : G[now_num]){
				int next_point = points[next_num];
				if(now_point < next_point){
					if(state[next_num]) state[next_num] = false;
					else state[next_num] = true;
				}
			}
		}
	}
	for(auto b : state) if(b == true) {cout << -1 << endl; return 0;}
	cout << ans.size() << endl;
	for(auto v : ans) cout << v+1 << endl;

}


0