結果

問題 No.1477 Lamps on Graph
ユーザー kwm_tkwm_t
提出日時 2021-04-18 16:07:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 174,408 KB
実行使用メモリ 10,224 KB
最終ジャッジ日時 2023-09-17 07:48:16
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,004 KB
testcase_01 AC 3 ms
5,720 KB
testcase_02 AC 3 ms
5,736 KB
testcase_03 AC 3 ms
5,720 KB
testcase_04 AC 4 ms
5,724 KB
testcase_05 AC 3 ms
5,804 KB
testcase_06 AC 3 ms
5,748 KB
testcase_07 AC 3 ms
5,764 KB
testcase_08 AC 3 ms
5,776 KB
testcase_09 AC 3 ms
5,720 KB
testcase_10 AC 3 ms
5,724 KB
testcase_11 AC 4 ms
5,828 KB
testcase_12 AC 39 ms
7,264 KB
testcase_13 AC 36 ms
7,216 KB
testcase_14 AC 45 ms
7,496 KB
testcase_15 AC 22 ms
6,672 KB
testcase_16 AC 15 ms
6,528 KB
testcase_17 AC 14 ms
6,596 KB
testcase_18 AC 33 ms
7,452 KB
testcase_19 AC 32 ms
7,220 KB
testcase_20 AC 15 ms
6,364 KB
testcase_21 AC 29 ms
7,296 KB
testcase_22 AC 11 ms
6,168 KB
testcase_23 AC 27 ms
6,888 KB
testcase_24 AC 51 ms
7,840 KB
testcase_25 AC 20 ms
6,544 KB
testcase_26 AC 46 ms
8,008 KB
testcase_27 AC 26 ms
6,796 KB
testcase_28 AC 29 ms
7,204 KB
testcase_29 AC 28 ms
6,904 KB
testcase_30 AC 18 ms
6,476 KB
testcase_31 AC 16 ms
6,516 KB
testcase_32 AC 54 ms
10,224 KB
testcase_33 AC 50 ms
9,252 KB
testcase_34 AC 46 ms
7,516 KB
testcase_35 AC 66 ms
8,940 KB
testcase_36 AC 67 ms
9,000 KB
testcase_37 AC 58 ms
9,020 KB
testcase_38 AC 60 ms
8,944 KB
testcase_39 AC 63 ms
8,932 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