結果
問題 |
No.408 五輪ピック
|
ユーザー |
|
提出日時 | 2016-08-14 13:19:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 144 ms / 5,000 ms |
コード長 | 824 bytes |
コンパイル時間 | 1,329 ms |
コンパイル使用メモリ | 160,884 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-11-07 16:42:21 |
合計ジャッジ時間 | 3,633 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d %d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> g[20000]; int color[20000]; int vis[20000][16]; bool dfs(int curr, int c, int s) { if (vis[curr][c]) return false; vis[curr][c] = true; if (curr != s) { if (c & 1 << color[curr]) return false; c |= 1 << color[curr]; } else { if (c != 0) return c == 15; } for (int next : g[curr]) { if (dfs(next, c, s)) return true; } return false; } int main() { int n, m; cin >> n >> m; srand(time(NULL)); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; g[u].push_back(v); g[v].push_back(u); } for (int i = 0; i < 50; i++) { memset(vis, false, sizeof(vis)); for (int i = 0; i < n; i++) { color[i] = rand() % 4; } if (dfs(0, 0, 0)) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }