結果

問題 No.408 五輪ピック
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-07 06:33:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 63,160 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-24 19:46:49
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
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;
int A[50001];//クエリを入れておく
int B[50001];
vector<int> g[20001];//辺の隣接リスト
vector<int> h[20001];//h[v][u]で 0 - u - vという辺の繋がりを表している 
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;
        printf("%d %d \n", a, 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 != B[i] && p != q && A[i] != q){
                    printf("YES\n"); return 0;
                }
            }
        }
    }
    printf("NO\n");
    return 0;
}
0