結果

問題 No.408 五輪ピック
ユーザー cormorancormoran
提出日時 2016-10-18 17:49:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,271 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 177,828 KB
実行使用メモリ 10,656 KB
最終ジャッジ日時 2024-05-02 02:37:55
合計ジャッジ時間 8,549 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()

template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    vector<vector<int>> E;
    bool dfs(int dep, int now, set<int> &visited, int start) {
        if(dep == 5 and now == start) return true;
        if(dep >= 5) return false;
        if(visited.count(now)) return false;
        bool flg = false;
        visited.insert(now);
        for(int nxt : E[now]) {            
            flg |= dfs(dep + 1, nxt, visited, start);
        }
        visited.erase(now);
        return flg;
    }
    
    bool solve() {
        int N, M; cin >> N >> M;
        E.resize(N);
        rep(i, M) {
            int a, b; cin >> a >> b;
            a--, b--;
            E[a].push_back(b);
            E[b].push_back(a);
        }
        bool flg = false;
        set<int> visited;
        cout << (dfs(0, 0, visited, 0) ? "YES" : "NO") << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0