結果

問題 No.629 グラフの中に眠る門松列
ユーザー nanae
提出日時 2018-01-05 22:00:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 68,172 KB
最終ジャッジ日時 2025-01-05 07:04:01
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5 WA * 1
other AC * 28 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

struct Edge {
    int u, v;
};

int n,m;
int a[1010];
Edge es[4010];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i+1];
    }
    
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        es[i] = Edge({u, v});
    }
    
    for (int i = 0; i < m; i++) {
        for (int j = i + 1; j < m; j++) {
            int a, b, c;
            a = b = c = 0;
            
            if (es[i].u == es[j].u) {
                a = es[i].v, b = es[i].u, c = es[j].v;
            }
            else if (es[i].u == es[j].v) {
                a = es[i].v, b = es[i].u, c = es[j].u;
            }
            else if (es[i].v == es[j].u) {
                a = es[i].u, b = es[i].v, c= es[j].v;
            }
            else if (es[i].v == es[j].v) {
                a = es[i].u, b = es[i].v, c = es[j].u;
            }
            
            if (a) {
                if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "NO" << endl;
    return 0;
}
0