結果

問題 No.629 グラフの中に眠る門松列
ユーザー SugarDragon5SugarDragon5
提出日時 2018-01-05 21:36:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,856 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 172,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 20:32:33
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 25 ms
4,380 KB
testcase_26 AC 30 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 6 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 3 ms
4,376 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int V,E;
vvi G;
vi vec;
bool dfs(vi vis){
    if(vis.size()==3){
        REP(i,3){
            FOR(j,i+1,3){
                if(vec[vis[i]]==vec[vis[j]]){
                    return false;
                }
            }
        }
        if(vec[vis[0]]<vec[vis[1]]&&vec[vis[1]]>vec[vis[2]]){
            return true;
        }
        if(vec[vis[0]]>vec[vis[1]]&&vec[vis[1]]<vec[vis[2]]){
            return true;
        }
        return false;
    }
    if(vis.size()==0){
        REP(i,V){
            vis.push_back(i);
            if(dfs(vis)){
                return true;
            }
            vis.pop_back();
        }
        return false;
    }
    int v=vec.back();
    REP(i,G[v].size()){
        int t=G[v][i];
        bool f=true;
        REP(j,vis.size()){
            if(vis[j]==t){
                f=false;
                break;
            }
        }
        if(f){
            vis.pb(t);
            if(dfs(vis)){
                return true;
            }
            vis.pop_back();
        }
    }
    return false;
}
int main(){
    cin>>V>>E;
    vec.resize(V);
    REP(i,V){
        cin>>vec[i];
        vec[i]--;
    }
    G.resize(V);
    REP(i,E){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vi temp;
    if(dfs(temp)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}
0