結果
問題 |
No.583 鉄道同好会
|
ユーザー |
![]() |
提出日時 | 2019-06-24 01:28:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 880 bytes |
コンパイル時間 | 1,177 ms |
コンパイル使用メモリ | 85,496 KB |
実行使用メモリ | 22,528 KB |
最終ジャッジ日時 | 2024-12-30 00:23:47 |
合計ジャッジ時間 | 26,216 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 TLE * 8 |
ソースコード
#include <iostream> #include <tuple> #include <algorithm> #include <vector> #include <map> #include <set> using namespace std; using ll = long long int; using P = tuple<int, int>; static const int NUM = 1000; int N, M; vector<vector<int>> adjacency_list(NUM); set<int> passed; bool dfs(int p, int num) { for (auto&& a: adjacency_list[p]) { int key = (p > a)? NUM * a + p: NUM * p + a; if (passed.find(key) != passed.end()) continue; passed.insert(key); if (dfs(a, num+1)) return true; passed.erase(key); } return num == M; } int main() { cin >> N >> M; for (int i = 0; i < M; ++i) { int Sa, Sb; cin >> Sa >> Sb; adjacency_list[Sa].push_back(Sb); adjacency_list[Sb].push_back(Sa); } for (int i = 0; i < N; ++i) { if (dfs(i, 0)) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }