結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-04-16 22:11:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,059 bytes |
コンパイル時間 | 2,317 ms |
コンパイル使用メモリ | 199,064 KB |
最終ジャッジ日時 | 2025-01-20 20:03:48 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d %d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:10:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | REP(i, 0, n) scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d %d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &k); | ~~~~~^~~~~~~~~~ main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &b); | ~~~~~^~~~~~~~~~
ソースコード
#include<bits/stdc++.h>#define REP(i,b,e) for(int i=(b);i<(e);i++)int main(){int n, m;scanf("%d %d", &n, &m);int a[n], in[n] = {};std::vector<int> links[n];REP(i, 0, n) scanf("%d", &a[i]);REP(i, 0, m){int u, v;scanf("%d %d", &u, &v);u--, v--;if(a[u]<a[v]){links[u].push_back(v);in[v]++;}else if(a[u]>a[v]){links[v].push_back(u);in[u]++;}}bool on[n] = {};int k;scanf("%d", &k);REP(i, 0, k){int b;scanf("%d", &b);on[b-1] = true;}std::queue<int> que;REP(i, 0, n) if(in[i]==0) que.push(i);std::vector<int> ans;while(!que.empty()){int from = que.front();que.pop();if(!on[from]){for(int to: links[from]){if(--in[to]==0) que.push(to);}}else{on[from] = !on[from];ans.push_back(from+1);for(int to: links[from]){on[to] = !on[to];if(--in[to]==0) que.push(to);}}}bool ok = true;REP(i, 0, n) if(on[i]) ok = false;if(!ok) puts("-1");else{printf("%ld\n", ans.size());for(int x: ans) printf("%d\n", x);}return 0;}