結果

問題 No.583 鉄道同好会
ユーザー mzkr
提出日時 2019-06-24 01:22:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 900 bytes
コンパイル時間 1,058 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 27,300 KB
最終ジャッジ日時 2024-12-30 00:00:04
合計ジャッジ時間 26,587 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

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