結果

問題 No.408 五輪ピック
ユーザー face4face4
提出日時 2019-11-22 14:50:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,210 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-19 10:14:55
合計ジャッジ時間 2,124 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 24 ms
6,944 KB
testcase_06 AC 16 ms
6,944 KB
testcase_07 AC 22 ms
6,944 KB
testcase_08 AC 17 ms
6,944 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 AC 15 ms
6,948 KB
testcase_11 AC 15 ms
6,944 KB
testcase_12 AC 26 ms
6,944 KB
testcase_13 AC 23 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 29 ms
6,944 KB
testcase_16 AC 25 ms
6,940 KB
testcase_17 AC 27 ms
6,944 KB
testcase_18 AC 28 ms
6,940 KB
testcase_19 AC 30 ms
6,940 KB
testcase_20 AC 9 ms
6,944 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 15 ms
6,940 KB
testcase_23 AC 40 ms
8,704 KB
testcase_24 AC 24 ms
6,944 KB
testcase_25 AC 29 ms
6,940 KB
testcase_26 AC 33 ms
6,940 KB
testcase_27 AC 30 ms
6,944 KB
testcase_28 AC 21 ms
6,940 KB
testcase_29 AC 21 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
using namespace std;

// 80MB?
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), v[n];
    set<int> s[n];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    for(int next : v[0]){
        for(int j : v[next]){
            if(j != 0)  s[j].insert(next);
        }
    }

    for(int i = 0; i < m; i++){
        int x = a[i], y = b[i];
        if(s[x].empty() || s[y].empty())    continue;
        bool c = s[x].count(y);
        bool d = s[y].count(x);
        if(c)   s[x].erase(y);
        if(d)   s[y].erase(x);
        // cout << x << ":";   for(int v : s[x])   cout << " " << v;
        // cout << endl;
        // cout << y << ":";   for(int v : s[y])   cout << " " << v;
        // cout << endl;
        if(s[x].empty() || s[y].empty() || (s[x].size() == 1 && s[x].size() == s[y].size() && *s[x].begin()==*s[y].begin())){
            if(c)   s[x].insert(y);
            if(d)   s[y].insert(x);
            continue;
        }
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}
0