結果
| 問題 |
No.1477 Lamps on Graph
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-07 10:18:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 225 ms / 2,000 ms |
| コード長 | 1,394 bytes |
| コンパイル時間 | 1,954 ms |
| コンパイル使用メモリ | 181,580 KB |
| 実行使用メモリ | 11,028 KB |
| 最終ジャッジ日時 | 2024-07-07 10:23:34 |
| 合計ジャッジ時間 | 6,700 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
#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;
}