結果
| 問題 |
No.1477 Lamps on Graph
|
| ユーザー |
y61mpnl
|
| 提出日時 | 2021-04-16 21:47:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,038 bytes |
| コンパイル時間 | 2,708 ms |
| コンパイル使用メモリ | 199,836 KB |
| 最終ジャッジ日時 | 2025-01-20 19:45:15 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 WA * 2 |
コンパイルメッセージ
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:9:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | REP(i, 0, n) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d %d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | 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];
REP(i, 0, n) scanf("%d", &a[i]);
int in[n] = {};
std::vector<int> links[n];
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{
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] ^= 1;
ans.push_back(from+1);
for(int to: links[from]){
on[to] ^= 1;
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;
}
y61mpnl