結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-04-18 16:06:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,680 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 176,472 KB |
実行使用メモリ | 10,292 KB |
最終ジャッジ日時 | 2024-07-04 04:38:29 |
合計ジャッジ時間 | 4,997 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#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; }