結果

問題 No.408 五輪ピック
ユーザー chakku
提出日時 2016-09-06 00:09:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,606 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 164,064 KB
実行使用メモリ 16,748 KB
最終ジャッジ日時 2024-11-15 20:29:57
合計ジャッジ時間 21,745 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int N,M;
vector<int> G[200001];
vector<bool> use;

bool dfs(int cur,int num,vector<int>& vis){
    if(num!=5 and cur==0){
        return false;
    }
    if(num==5){
        if(cur==0) return true;
        else return false;
    }

    for(int v : vis) if(v == cur ) return false;

    //cout << cur << " " << num << "  : " << vis << endl;

    vector<int> nv(vis);
    nv.push_back(cur);

    for(int v : G[cur]){
        if(dfs(v,num+1,nv)){
            return true;
        }
    }
    return false;
}

int main(){
    cin>>N>>M;
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }


    int c=0;
    for(int sv : G[0]){
        //debug(sv);
        // use.assign(N,false);
        vector<int> v;
        bool f=dfs(sv,1,v);
        //debug(f);
        if(f){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}
0