結果

問題 No.408 五輪ピック
ユーザー cormorancormoran
提出日時 2016-10-19 09:26:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,811 ms / 5,000 ms
コード長 2,508 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 180,200 KB
実行使用メモリ 13,380 KB
最終ジャッジ日時 2023-08-14 16:26:12
合計ジャッジ時間 7,663 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 33 ms
8,744 KB
testcase_06 AC 10 ms
5,880 KB
testcase_07 AC 18 ms
6,932 KB
testcase_08 AC 21 ms
6,824 KB
testcase_09 AC 18 ms
6,484 KB
testcase_10 AC 12 ms
5,908 KB
testcase_11 AC 11 ms
5,608 KB
testcase_12 AC 21 ms
7,448 KB
testcase_13 AC 30 ms
8,392 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 42 ms
10,220 KB
testcase_16 AC 48 ms
8,432 KB
testcase_17 AC 29 ms
8,164 KB
testcase_18 AC 28 ms
8,200 KB
testcase_19 AC 27 ms
8,244 KB
testcase_20 AC 6 ms
4,628 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 9 ms
5,664 KB
testcase_23 AC 55 ms
13,380 KB
testcase_24 AC 3,811 ms
10,152 KB
testcase_25 AC 43 ms
10,460 KB
testcase_26 AC 26 ms
8,620 KB
testcase_27 AC 46 ms
10,324 KB
testcase_28 AC 20 ms
7,232 KB
testcase_29 AC 20 ms
7,484 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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]) {
                if(b != 0) 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 = aa->first, vb = bb->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;
                        cerr << "hoo" << endl;
                    }
                    else {
                        assert(a_road_num == 1 and b_road_num == 1);
                        auto node_a = aa->second.begin(); while(*node_a == vb and node_a != aa->second.end()) node_a++;
                        auto node_b = bb->second.begin(); while(*node_b == va and node_b != bb->second.end()) node_b++;
                        flg |= (not bb->second.count(*node_a) and not aa->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