結果
| 問題 | No.2236 Lights Out On Simple Graph |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-03 23:17:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,251 bytes |
| 記録 | |
| コンパイル時間 | 999 ms |
| コンパイル使用メモリ | 99,112 KB |
| 最終ジャッジ日時 | 2025-02-11 04:30:49 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 TLE * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d %d", &as[i], &bs[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &cs[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
int as[64], bs[64], cs[64];
int main() {
int n, i, a, b, d, m;
LL v, one=1, nv;
scanf("%d %d", &n, &m);
for (i=0; i<m; i++) {
scanf("%d %d", &as[i], &bs[i]);
as[i]--; bs[i]--;
}
v=0;
a=0;
for (i=0; i<n; i++) {
scanf("%d", &cs[i]);
a+=cs[i];
}
if (a&1) {
printf("-1\n"); return 0;
}
for (i=n-1; i>=0; i--) {
v=v*2+cs[i];
}
queue<LL> q;
map<LL, int> dp;
dp[v]=0;
q.push(v);
while(!q.empty()) {
if (dp.count(0)) break;
v = q.front();
d = dp[v]+1;
q.pop();
for (i=0; i<m; i++) {
a=as[i]; b=bs[i];
nv = v^(one<<a)^(one<<b);
if (dp.count(nv)) continue;
dp[nv]=d;
q.push(nv);
}
}
if (dp.count(0)) printf("%d\n", dp[0]);
else printf("-1\n");
return 0;
}