結果

問題 No.408 五輪ピック
ユーザー tnakao0123tnakao0123
提出日時 2016-08-07 00:50:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,256 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-24 19:39:35
合計ジャッジ時間 8,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,856 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 24 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 21 ms
5,376 KB
testcase_10 AC 17 ms
5,376 KB
testcase_11 AC 16 ms
5,376 KB
testcase_12 AC 27 ms
5,376 KB
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 27 ms
5,376 KB
testcase_17 AC 29 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 29 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 14 ms
5,376 KB
testcase_23 AC 30 ms
5,376 KB
testcase_24 AC 20 ms
5,376 KB
testcase_25 AC 154 ms
5,376 KB
testcase_26 AC 35 ms
5,376 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 408.cc: No.408 五輪ピック - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20000;
const int L = 5;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
bool used[MAX_N];

/* subroutines */

bool rec(int u, int ul, int st) {
  vi &nbru = nbrs[u];
  int vl = ul + 1;

  for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
    int &v = *vit;
    if (v == st) {
      if (vl == L) return true;
    }
    else if (! used[v] && vl < L) {
      used[v] = true;
      if (rec(v, vl, st)) return true;
      used[v] = false;
    }
  }
  return false;
}

/* main */

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    ai--, bi--;
    nbrs[ai].push_back(bi);
    nbrs[bi].push_back(ai);
  }

  used[0] = true;
  bool ok = rec(0, 0, 0);

  cout << (ok ? "YES" : "NO") << endl;

  return 0;
}
0