結果

問題 No.1477 Lamps on Graph
ユーザー ayoiyouyoeyoayoiyouyoeyo
提出日時 2021-04-16 22:39:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 2,213 bytes
コンパイル時間 3,562 ms
コンパイル使用メモリ 177,316 KB
実行使用メモリ 12,588 KB
最終ジャッジ日時 2023-09-16 01:42:52
合計ジャッジ時間 9,881 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 108 ms
7,572 KB
testcase_13 AC 112 ms
7,092 KB
testcase_14 AC 131 ms
8,284 KB
testcase_15 AC 53 ms
5,152 KB
testcase_16 AC 40 ms
5,508 KB
testcase_17 AC 43 ms
5,388 KB
testcase_18 AC 168 ms
9,604 KB
testcase_19 AC 104 ms
7,644 KB
testcase_20 AC 39 ms
4,740 KB
testcase_21 AC 146 ms
8,156 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 71 ms
5,636 KB
testcase_24 AC 161 ms
9,008 KB
testcase_25 AC 51 ms
5,112 KB
testcase_26 AC 156 ms
9,444 KB
testcase_27 AC 61 ms
5,660 KB
testcase_28 AC 78 ms
6,952 KB
testcase_29 AC 79 ms
5,864 KB
testcase_30 AC 98 ms
6,328 KB
testcase_31 AC 59 ms
5,740 KB
testcase_32 AC 264 ms
12,588 KB
testcase_33 AC 215 ms
11,516 KB
testcase_34 AC 245 ms
9,640 KB
testcase_35 AC 215 ms
11,260 KB
testcase_36 AC 208 ms
11,200 KB
testcase_37 AC 159 ms
11,004 KB
testcase_38 AC 178 ms
11,332 KB
testcase_39 AC 207 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
#include<random>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e17;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll id;
	ll fr;
	ll to;
	ll d;
};

using mint = modint;

typedef vector<ll> vll;
typedef vector <vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

vmint f, finv, inv;

void cominit(ll N) {
	ll MOD = modint::mod();//デフォルトが998244353に注意

	f.assign(N + 1, 1);
	finv.assign(N + 1, 1);
	inv.assign(N + 1, 1);
	inv[1] = 1;

	repn(i, N) {
		f[i] = f[i - 1] * i;
		if (i > 1)inv[i] = -inv[MOD % i] * (MOD / i);
		finv[i] = finv[i - 1] * inv[i];
	}
}

mint com(ll a, ll b) {
	if (a < 0 || b < 0 || a < b) { return 0; }
	return f[a] * finv[b] * finv[a - b];
}


/////////////////////////////////////


int main() {
	ll N, M;
	cin >> N >> M;
	vll A(N);
	rep(i, N)cin >> A[i];

	vvll g(N);
	rep(i, M) {
		ll u, v;
		cin >> u >> v;
		u--; v--;

		if (A[u] < A[v]) { g[u].push_back(v); }
		if (A[u] > A[v]) { g[v].push_back(u); }
	}

	vll on(N);
	ll K;
	cin >> K;
	rep(i, K) {
		ll b;
		cin >> b;
		on[b - 1]++;
	}

	vector<P> p(N);
	rep(i, N)p[i] = { A[i],i };
	sort(p.begin(), p.end());

	vll lis;

	rep(i, N) {
		ll x = p[i].second;
		if (on[x] == 0) { continue; }
		on[x] = 0;
		lis.push_back(x);
		for (ll y : g[x]) {
			on[y] = 1 - on[y];
		}
	}

	cout << lis.size() << endl;
	for (ll x : lis) {
		cout << x + 1 << endl;
	}


}
0