結果

問題 No.583 鉄道同好会
コンテスト
ユーザー mzkr
提出日時 2019-06-24 01:22:50
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 900 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 559 ms
コンパイル使用メモリ 102,272 KB
実行使用メモリ 15,776 KB
最終ジャッジ日時 2026-06-03 17:31:26
合計ジャッジ時間 4,621 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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