結果

問題 No.408 五輪ピック
ユーザー btkbtk
提出日時 2016-08-03 01:09:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 1,320 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 180,740 KB
実行使用メモリ 8,208 KB
最終ジャッジ日時 2024-04-24 15:11:24
合計ジャッジ時間 3,761 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 37 ms
6,272 KB
testcase_06 AC 20 ms
6,016 KB
testcase_07 AC 30 ms
5,884 KB
testcase_08 AC 26 ms
5,376 KB
testcase_09 AC 27 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 19 ms
5,376 KB
testcase_12 AC 35 ms
5,972 KB
testcase_13 AC 36 ms
6,144 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 37 ms
6,400 KB
testcase_16 AC 39 ms
6,400 KB
testcase_17 AC 39 ms
6,272 KB
testcase_18 AC 39 ms
6,272 KB
testcase_19 AC 41 ms
6,400 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 17 ms
5,760 KB
testcase_23 AC 50 ms
8,208 KB
testcase_24 AC 31 ms
6,912 KB
testcase_25 AC 36 ms
6,272 KB
testcase_26 AC 43 ms
6,872 KB
testcase_27 AC 37 ms
6,400 KB
testcase_28 AC 23 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef vector<int> V;
typedef vector<V> Graph;

void check(int N,int M,V A,V B){
    assert(2<=N&&N<=20000);
    assert(0<=M&&M<=min(N*(N-1)/2,50000));
    using P=pair<int,int>;
    set<P> s;
    for(int i=0;i<M;i++){
        assert(A[i]!=B[i]);
        P p(min(A[i],B[i]),max(A[i],B[i]));
        assert(s.count(p)==0);
        s.insert(p);
    }
}


int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(M),B(M);
    for(int i=0;i<M;A[i]--,B[i]--,i++)cin>>A[i]>>B[i];
    check(N,M,A,B);
    Graph g(N);
    for(int i=0;i<M;i++){
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }

    vector<bool> near(N,false);
    for(auto &v:g[0])near[v]=true;
    vector<set<int>> V(N);
    for(int i=0;i<M;i++){
        int x=A[i],y=B[i];
        if(near[x]&&V[y].size()<3)V[y].insert(x);
        swap(x,y);
        if(near[x]&&V[y].size()<3)V[y].insert(x);
    }
    for(int i=0;i<M;i++){
        int x=A[i],y=B[i];
        if(x*y>0)
            for(auto &s:V[x])
                for(auto &t:V[y])
                    if(s!=t&&s!=y&&t!=x){
                        cout<<"YES"<<endl;
                        return 0;
                    }
    }
        
    cout<<"NO"<<endl;
    return 0;
}
0