結果

問題 No.408 五輪ピック
ユーザー tottoripapertottoripaper
提出日時 2016-10-21 14:35:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,467 bytes
コンパイル時間 4,038 ms
コンパイル使用メモリ 171,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 22:00:12
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 8 ms
6,940 KB
testcase_07 AC 12 ms
6,944 KB
testcase_08 AC 9 ms
6,944 KB
testcase_09 AC 10 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 13 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 13 ms
6,944 KB
testcase_19 AC 15 ms
6,940 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 8 ms
6,940 KB
testcase_23 AC 17 ms
6,940 KB
testcase_24 WA -
testcase_25 AC 11 ms
6,940 KB
testcase_26 AC 18 ms
6,940 KB
testcase_27 AC 12 ms
6,940 KB
testcase_28 AC 9 ms
6,944 KB
testcase_29 AC 9 ms
6,944 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
vector<int> G[20000];
std::stack<int> st;
vector<P> es;
int as[20000], bs[20000];

void bfs(){
    while(!st.empty()){
        int p = st.top(); st.pop();
        
        for(int to : G[p]){
            if(to == 0){continue;}

            ++as[to];
            bs[to] = p;
        }
    }

    for(int i=0;i<N;++i){
        if(as[i] > 0){st.push(i);}
    }
}

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int A, B;
        std::cin >> A >> B;

        --A; --B;
        
        G[A].emplace_back(B);
        G[B].emplace_back(A);

        es.emplace_back(A, B);
    }

    st.push(0);
    bfs();
    memset(as, 0, sizeof(as));
    memset(bs, 0, sizeof(bs));
    bfs();

    bool isOk = false;
    for(const P& e : es){
        int u, v;
        tie(u, v) = e;
        
        if((as[u] >= 1 && as[v] >= 1) &&
           ((as[u] > 1) || (as[v] > 1) ||
            (bs[u] != bs[v]))){
            isOk = true;
            break;
        }
    }

    if(isOk){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}
0