結果

問題 No.583 鉄道同好会
ユーザー mzkrmzkr
提出日時 2019-06-23 23:39:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,047 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 79,492 KB
実行使用メモリ 9,792 KB
最終ジャッジ日時 2023-08-28 15:20:25
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

using namespace std;
using ll = long long int;
using P = tuple<int, int, bool>;

int N, M;
vector<P> WAY;

bool dfs(int p, int num) {
  // cout << num << endl;
  for (auto&& w: WAY) {
    int& a = get<0>(w);
    int& b = get<1>(w);
    bool& c = get<2>(w);
    if (a != p || !c) continue;
    c = false;
    if (dfs(b, num+1)) return true;
    c = true;
  }
  for (auto&& w: WAY) {
    int& a = get<0>(w);
    int& b = get<1>(w);
    bool& c = get<2>(w);
    if (b != p || !c) continue;
    c = false;
    if (dfs(a, num+1)) return true;
    c = true;
  }
  return num == M;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int Sa, Sb;
    cin >> Sa >> Sb;
    WAY.push_back(make_tuple(Sa, Sb, true));
  }
  int a, b;
  bool c;
  for (auto&& w: WAY) {
    int a, b;
    bool c;
    tie(a, b, c) = w;
  }
  for (int i = 0; i < N; ++i) {
    if (dfs(i, 0)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
0