結果

問題 No.408 五輪ピック
ユーザー rapurasurapurasu
提出日時 2016-08-06 00:01:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,691 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 161,124 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-24 20:03:28
合計ジャッジ時間 2,671 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 22 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 22 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 19 ms
5,376 KB
testcase_10 AC 15 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 22 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 21 ms
5,376 KB
testcase_16 AC 25 ms
5,376 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 27 ms
5,376 KB
testcase_19 AC 29 ms
5,376 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 32 ms
5,376 KB
testcase_24 AC 19 ms
5,376 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 30 ms
5,504 KB
testcase_27 AC 23 ms
5,376 KB
testcase_28 AC 18 ms
5,376 KB
testcase_29 AC 17 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;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
bool dp[6][20001];
int p1[6][20001];
vector<int>v[20001];
int main(){
        int N,M;
        cin>>N>>M;
        REP(i,M){
          int a,b;
          cin>>a>>b;
          v[a].push_back(b);
          v[b].push_back(a);
        }
	REP(i,6){
	   REP(j,20001){
             dp[i][j]=false;
	   }
	}
        REP(i,6){
	  REP(j,20001){
             p1[i][j]=-1;
	   }
	}
        dp[0][1]=true;
        REP(i,5){
            REP(j,N+1){
               if(dp[i][j]){
                  REP(k,v[j].size()){
                      int x=v[j][k];
                      if(x!=1){
                         if(p1[i][j]!=x){
                            if(p1[i+1][x]!=-1){
                               p1[i+1][x]=-2;
                            }else{
                               p1[i+1][x]=j;
                            }
                            dp[i+1][x]=true;
                         }
                      }
                  }
               }
            }
        }
        int check=0;
        REP(i,N+1){
            if(i==1)continue;
            if(dp[4][i]==true){
               REP(j,v[i].size()){
                   if(v[i][j]==1)check++;
               }
            }
            if(check>=2)break;
        }
/*
        REP(i,6){
           REP(j,N+1){
           cout<<dp[i][j];
           }
           cout<<endl;
        }
*/
        if(check>=2){
           cout<<"YES"<<endl;
        }else{
           cout<<"NO"<<endl;
        }
	
	return(0);
}
0