結果

問題 No.583 鉄道同好会
ユーザー mzkrmzkr
提出日時 2019-06-24 01:28:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 880 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 85,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 17:41:11
合計ジャッジ時間 4,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0