結果

問題 No.408 五輪ピック
ユーザー face4
提出日時 2019-11-22 14:39:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,235 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 81,332 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-10-11 02:34:31
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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;
        if(s[x].size() == 1 && *s[x].begin() == y || *s[y].begin() == x)    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);
        if(s[x].size() != s[y].size()){
            cout << "YES" << endl;
            return 0;
        }
        bool same = true;
        for(auto it = s[x].begin(), it2 = s[y].begin(); it != s[x].end(); it++, it2++){
            same &= *it == *it2;
        }
        if(c)   s[x].insert(y);
        if(d)   s[y].insert(x);
        if(same)    continue;
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}
0