結果

問題 No.408 五輪ピック
ユーザー mamekinmamekin
提出日時 2016-10-05 20:18:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 2,163 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 113,968 KB
実行使用メモリ 9,248 KB
最終ジャッジ日時 2023-08-13 23:17:09
合計ジャッジ時間 3,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 24 ms
4,828 KB
testcase_06 AC 17 ms
5,180 KB
testcase_07 AC 24 ms
5,116 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 20 ms
4,448 KB
testcase_10 AC 16 ms
4,636 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 27 ms
5,260 KB
testcase_13 AC 23 ms
4,392 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 32 ms
5,996 KB
testcase_16 AC 25 ms
4,392 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 29 ms
4,540 KB
testcase_19 AC 31 ms
5,088 KB
testcase_20 AC 9 ms
4,420 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 15 ms
5,288 KB
testcase_23 AC 51 ms
9,248 KB
testcase_24 AC 33 ms
7,492 KB
testcase_25 AC 30 ms
6,504 KB
testcase_26 AC 33 ms
5,708 KB
testcase_27 AC 33 ms
6,532 KB
testcase_28 AC 25 ms
5,924 KB
testcase_29 AC 25 ms
6,116 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class RollingHash
{
private:
    static const int X[], Y[], M[];
    long long hash[3];
public:
    RollingHash(){
        for(int i=0; i<3; ++i)
            hash[i] = 0;
    }
    void push_back(int a){
        for(int i=0; i<3; ++i){
            hash[i] *= X[i];
            hash[i] += a;
            hash[i] %= M[i];
        }
    }
    bool operator==(const RollingHash& rh) const{
        for(int i=0; i<3; ++i){
            if(hash[i] != rh.hash[i])
                return false;
        }
        return true;
    }
    bool operator!=(const RollingHash& rh) const{
        return !(*this == rh);
    }
};
const int RollingHash::X[] = {1685440109, 1389328937, 1813126193}; // 素数
const int RollingHash::Y[] = {1835226359, 1406652555,  643336582}; // X * Y == 1 (mod M)
const int RollingHash::M[] = {2000000087, 2000000089, 2000000099}; // 合同式の法(素数)


int main()
{
    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    vector<vector<int> > edges(n);
    for(int i=0; i<m; ++i){
        cin >> a[i] >> b[i];
        -- a[i];
        -- b[i];
        edges[a[i]].push_back(b[i]);
        edges[b[i]].push_back(a[i]);
    }

    vector<set<int> > s(n);
    for(int x : edges[0]){
        for(int y : edges[x]){
            s[y].insert(x);
        }
    }

    for(int i=0; i<m; ++i){
        if(a[i] == 0 || b[i] == 0)
            continue;
        if(s[a[i]].empty() || s[b[i]].empty())
            continue;
        if(s[a[i]].size() == 1 && s[a[i]] == s[b[i]])
            continue;
        if(s[a[i]] == set<int>{ b[i] } || s[b[i]] == set<int>{ a[i] })
            continue;

        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;
    return 0;
}
0