結果

問題 No.1477 Lamps on Graph
ユーザー kwm_tkwm_t
提出日時 2021-04-18 16:06:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,680 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 175,660 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-09-17 07:47:58
合計ジャッジ時間 5,757 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,740 KB
testcase_01 AC 4 ms
6,008 KB
testcase_02 AC 3 ms
5,896 KB
testcase_03 AC 3 ms
5,736 KB
testcase_04 AC 3 ms
5,736 KB
testcase_05 AC 3 ms
5,788 KB
testcase_06 AC 4 ms
5,736 KB
testcase_07 AC 3 ms
5,828 KB
testcase_08 AC 3 ms
5,784 KB
testcase_09 AC 4 ms
5,736 KB
testcase_10 AC 3 ms
5,672 KB
testcase_11 AC 3 ms
5,884 KB
testcase_12 AC 37 ms
7,364 KB
testcase_13 AC 35 ms
7,200 KB
testcase_14 AC 43 ms
7,488 KB
testcase_15 AC 22 ms
6,648 KB
testcase_16 AC 15 ms
6,580 KB
testcase_17 AC 14 ms
6,648 KB
testcase_18 AC 33 ms
7,412 KB
testcase_19 AC 31 ms
7,456 KB
testcase_20 AC 15 ms
6,508 KB
testcase_21 AC 29 ms
7,320 KB
testcase_22 AC 11 ms
6,080 KB
testcase_23 AC 27 ms
6,812 KB
testcase_24 AC 48 ms
7,732 KB
testcase_25 AC 19 ms
6,540 KB
testcase_26 AC 43 ms
8,088 KB
testcase_27 AC 24 ms
6,876 KB
testcase_28 AC 28 ms
7,056 KB
testcase_29 AC 27 ms
6,848 KB
testcase_30 AC 18 ms
6,496 KB
testcase_31 AC 15 ms
6,576 KB
testcase_32 AC 53 ms
10,220 KB
testcase_33 AC 51 ms
9,244 KB
testcase_34 AC 46 ms
7,404 KB
testcase_35 AC 63 ms
8,908 KB
testcase_36 AC 59 ms
8,908 KB
testcase_37 AC 53 ms
8,928 KB
testcase_38 AC 55 ms
8,988 KB
testcase_39 AC 60 ms
9,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>to[100005];
std::vector<int>topological_sort(int V) {
	std::vector<int>h(V);
	for (int i = 0; i < V; ++i) for (auto e : to[i]) ++h[e];
	std::stack<int>st;
	std::vector<int>ans;
	for (int i = 0; i < V; ++i) if (h[i] == 0) st.push(i);
	while (!st.empty()) {
		int v = st.top(); st.pop();
		ans.push_back(v);
		for (auto u : to[v]) {
			--h[u];
			if (h[u] == 0) st.push(u);
		}
	}
	return ans;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<int>a(n);
	rep(i, n) { cin >> a[i]; }
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		int x = a[u];
		int y = a[v];
		if (x > y) { to[v].push_back(u); }
		else if (x < y) { to[u].push_back(v); }
	}
	vector<bool>b(n);//false消灯
	int k;
	cin >> k;
	rep(i, k) {
		int num;
		cin >> num;
		num--;
		b[num] = true;
	}
	auto sv = topological_sort(n);
	vector<int>vans;
	rep(i, n) {
		if (!b[sv[i]]) { continue; }
		b[sv[i]] = false;
		vans.push_back(sv[i] + 1);
		for (auto v : to[sv[i]]) {
			b[v] = !b[v];
		}
	}
	cout << vans.size() << endl;
	rep(i, vans.size()) {
		cout << vans[i] << endl;
	}
	return 0;
}
0