結果

問題 No.583 鉄道同好会
ユーザー mzkrmzkr
提出日時 2019-06-24 01:22:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 900 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 12,336 KB
最終ジャッジ日時 2023-08-28 17:33:00
合計ジャッジ時間 4,513 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 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>

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);
map<int, bool> 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[key]) continue;
    passed[key] = false;
    if (dfs(a, num+1)) return true;
    passed[key] = true;
  }
  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);
    passed.insert(make_pair(NUM*Sa+Sb, true));
  }
  for (int i = 0; i < N; ++i) {
    if (dfs(i, 0)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
0