結果

問題 No.408 五輪ピック
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-07 06:21:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,275 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 63,164 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 19:46:40
合計ジャッジ時間 5,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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 3 ms
5,376 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 5 ms
5,376 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         int a, b; scanf("%d %d", &a, &b);
      |                   ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n, m;
vector<int> g[20001];
vector<int> h[20001];
int A[20001];
int B[20001];
int main(void){
    cin >> n >> m;
    rep(i, m){
        int a, b; scanf("%d %d", &a, &b);
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        A[i] = a; B[i] = b;
    }

    //1 - u - vとなるような辺を見つける
    for(int u : g[0]){
        for (int v : g[u]){
            //頂点に戻るようなものは入れない
            if(v != 0) h[v].push_back(u);
        }
    }

    //クエリで与えられた辺を一つずつ見ていき、辺の両端の点が1からの距離が2の点であり、
    //かつ閉路を満たすものであるかどうかを調べている
    for (int i = 0; i < m; ++i){
        if(A[i] == 0 || B[i] == 0) continue;
        if(h[A[i]].size() > 3 && h[B[i]].size() > 3){
            printf("YES\n"); return 0;
        }
        for (int p : h[A[i]]){
            for (int q : h[B[i]]){
                if(p != A[i] && p != q && B[i] != q){
                    printf("YES\n"); return 0;
                }
            }
        }
    }
    printf("NO\n");
    return 0;
}
0