結果

問題 No.408 五輪ピック
ユーザー kimiyukikimiyuki
提出日時 2016-10-18 18:11:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,152 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 85,236 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-05-02 02:41:00
合計ジャッジ時間 2,366 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 27 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 23 ms
5,376 KB
testcase_08 AC 19 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 27 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 35 ms
6,144 KB
testcase_16 AC 31 ms
5,376 KB
testcase_17 AC 30 ms
5,376 KB
testcase_18 AC 31 ms
5,376 KB
testcase_19 AC 35 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 65 ms
11,264 KB
testcase_24 WA -
testcase_25 AC 35 ms
6,400 KB
testcase_26 AC 32 ms
5,760 KB
testcase_27 WA -
testcase_28 AC 29 ms
6,272 KB
testcase_29 AC 31 ms
6,272 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > g(n);
    repeat (i,m) {
        int a, b; cin >> a >> b; -- a; -- b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    const int root = 0;
    set<int> d1; for (int i : g[root]) d1.insert(i);
    set<int> d2; for (int i : g[root]) for (int j : g[i]) if (j != root) d2.insert(j);
    vector<set<int> > g1(n); repeat (i,n) for (int j : g[i]) if (d1.count(j)) g1[i].insert(j);
    bool ans = false;
    for (int i : d2) for (int j : d2) if (i < j) {
        bool g1_i_count_j = g1[i].count(j); g1[i].erase(j);
        bool g1_j_count_i = g1[j].count(i); g1[j].erase(i);
        if (not g1[i].empty() and not g1[j].empty()) {
            if (not (g1[i].size() == 1 and g1[j].size() == 1 and g1[i] == g1[j])) {
                ans = true;
            }
        }
        if (g1_i_count_j) g1[i].insert(j);
        if (g1_j_count_i) g1[j].insert(i);
        if (ans) goto done;
    }
done:
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}
0