結果

問題 No.408 五輪ピック
ユーザー どららどらら
提出日時 2016-08-06 01:52:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,347 ms / 5,000 ms
コード長 1,780 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 83,392 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-24 17:15:01
合計ジャッジ時間 9,330 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,248 KB
testcase_01 AC 12 ms
5,376 KB
testcase_02 AC 13 ms
5,376 KB
testcase_03 AC 13 ms
5,376 KB
testcase_04 AC 12 ms
5,376 KB
testcase_05 AC 690 ms
6,144 KB
testcase_06 AC 135 ms
6,016 KB
testcase_07 AC 120 ms
6,144 KB
testcase_08 AC 203 ms
5,760 KB
testcase_09 AC 105 ms
5,888 KB
testcase_10 AC 94 ms
5,888 KB
testcase_11 AC 86 ms
5,760 KB
testcase_12 AC 118 ms
6,272 KB
testcase_13 AC 587 ms
6,144 KB
testcase_14 AC 51 ms
5,376 KB
testcase_15 AC 702 ms
6,144 KB
testcase_16 AC 473 ms
6,144 KB
testcase_17 AC 211 ms
6,272 KB
testcase_18 AC 139 ms
6,272 KB
testcase_19 AC 133 ms
6,400 KB
testcase_20 AC 82 ms
5,632 KB
testcase_21 AC 59 ms
5,376 KB
testcase_22 AC 127 ms
5,888 KB
testcase_23 AC 1,347 ms
6,528 KB
testcase_24 AC 408 ms
6,016 KB
testcase_25 AC 390 ms
6,144 KB
testcase_26 AC 151 ms
6,656 KB
testcase_27 AC 401 ms
6,052 KB
testcase_28 AC 319 ms
6,016 KB
testcase_29 AC 320 ms
5,888 KB
testcase_30 AC 12 ms
5,376 KB
testcase_31 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

vector<int> v[20005];
int A[50005], B[50005];

int color[20005];
int dp[(1<<4)][20005];


int main(){
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  rep(i,M){
    cin >> A[i] >> B[i];
    v[A[i]].push_back(B[i]);
    v[B[i]].push_back(A[i]);
  }

  bool ret = false;
  rep(t,200){
    rep(i,N+1) color[i] = rand()%4;
    //REP(i,1,N+1) cout << color[i] << " "; cout << endl;
    
    rep(i,(1<<4)) rep(j,20005) dp[i][j] = 0;
    rep(i,v[1].size()){
      dp[(1<<(color[v[1][i]]))][v[1][i]] = 1;
      //cout << "init:" << color[v[1][i]] << " " << v[1][i] << endl;
    }
    rep(i,(1<<4)){
      rep(j,N+1){
        if(dp[i][j] == 1){
          rep(k,v[j].size()){
            if(v[j][k] == 1) continue;
            //cout << "cand:" << j << "->" << v[j][k] << " " << i << endl;
            if(((i>>color[v[j][k]])&1) == 0){
              //cout << "add:" << (i | (1<<(color[v[j][k]]))) << " " << v[j][k] << endl;
              dp[i | (1<<(color[v[j][k]]))][v[j][k]] = 1;
            }
          }
        }
      }
    }

    rep(i,N+1){
      if(dp[(1<<4)-1][i] == 1){
        //cout << i << endl;
        rep(j,v[i].size()) if(v[i][j] == 1) ret = true;
      }
    }
  }

  if(ret) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

0