結果

問題 No.408 五輪ピック
ユーザー cormorancormoran
提出日時 2016-10-18 19:59:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,274 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 182,584 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2024-05-02 02:46:25
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 2 ms
5,376 KB
testcase_05 AC 47 ms
8,704 KB
testcase_06 AC 15 ms
6,272 KB
testcase_07 AC 27 ms
7,168 KB
testcase_08 AC 30 ms
6,912 KB
testcase_09 AC 25 ms
6,608 KB
testcase_10 AC 15 ms
6,144 KB
testcase_11 AC 16 ms
5,888 KB
testcase_12 AC 31 ms
7,808 KB
testcase_13 AC 43 ms
8,320 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 63 ms
10,112 KB
testcase_16 AC 51 ms
8,448 KB
testcase_17 AC 39 ms
8,320 KB
testcase_18 AC 42 ms
8,320 KB
testcase_19 AC 35 ms
8,576 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 14 ms
6,144 KB
testcase_23 AC 102 ms
14,336 KB
testcase_24 WA -
testcase_25 AC 70 ms
10,496 KB
testcase_26 AC 40 ms
8,832 KB
testcase_27 AC 70 ms
10,368 KB
testcase_28 AC 31 ms
7,936 KB
testcase_29 AC 37 ms
7,808 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()

template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    vector<set<int>> E;
    bool solve() {
        int N, M; cin >> N >> M;
        E.resize(N);
        rep(i, M) {
            int a, b; cin >> a >> b;
            a--, b--;
            E[a].insert(b);
            E[b].insert(a);
        }

        map<int, set<int>> reachable_two; // mp[i] : 0から2回でiに達する道 (全ての場合の数, 中間ノード)

        for(auto a : E[0]) {
            for(auto b : E[a]) {
                reachable_two[b].insert(a);
            }
        }
        bool flg = false;
        for(auto a = reachable_two.begin(); a != reachable_two.end(); a++) {
            for(auto b = reachable_two.begin(); b != a; b++) {
                if(E[a->first].count(b->first)) {
                    decltype(a) aa, bb;
                    aa = a;
                    bb = b;
                                        
                    if(aa->second.size() > bb->second.size()) swap(aa, bb);

                    int va = a->first, vb = b->first; // node
                    int a_road_num = aa->second.size() - (aa->second.count(vb));
                    int b_road_num = bb->second.size() - (aa->second.count(va));

                    if(a_road_num == 0 or b_road_num == 0) continue;
                    else if(a_road_num >= 2 or b_road_num >= 2) flg = true;
                    else {
                        assert(a_road_num == 1 and b_road_num == 1);
                        int node_a = *a->second.begin();
                        int node_b = *b->second.begin();
                        flg |= (not b->second.count(node_a) and not a->second.count(node_b));
                    }
                }
                if(flg) goto END;
            }
        }
  END:;
        cout << (flg ? "YES" : "NO") << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0