結果

問題 No.408 五輪ピック
ユーザー nanophoto12nanophoto12
提出日時 2016-08-15 14:46:29
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,657 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 89,824 KB
実行使用メモリ 817,376 KB
最終ジャッジ日時 2024-04-25 07:23:47
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,632 KB
testcase_01 AC 3 ms
5,632 KB
testcase_02 AC 3 ms
5,632 KB
testcase_03 AC 3 ms
5,632 KB
testcase_04 AC 3 ms
5,632 KB
testcase_05 MLE -
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 <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>

static const int MAX_N = 100000;
vector<int> g[MAX_N];

struct hist
{
    int c;
    int v[5];
    
    bool ok(int n)
    {
        if(c != 5)
        {
            return false;
        }
        if(n == 1)
        {
            return true;
        }
        return false;
    }
    
    bool can(int n)
    {
        if(c >= 5)
        {
            return false;
        }
        for(int i = 0;i < c;i++)
        {
            if(v[i] == n)
            {
                return false;
            }
        }
        return true;
    }
    
    int last() const
    {
        return v[c-1];
    }
    
    hist add(int n)
    {
        hist next = *this;
        next.v[next.c] = n;
        next.c++;
        return next;
    }
};

int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++)
    {
        int f, s;
        cin >> f >> s;
        g[f].push_back(s);
        g[s].push_back(f);
    }
    queue<hist> q;
    q.push({1, 1});
    while(!q.empty())
    {
        auto s = q.front();
        q.pop();
        for(auto& r : g[s.last()])
        {
            if(s.ok(r))
            {
                cout << "YES" << endl;
                return 0;
            }
            if(!s.can(r))
            {
                continue;
            }
            q.push(s.add(r));
        }
    }
    cout << "NO" << endl;
    return 0;
}
0