結果

問題 No.408 五輪ピック
ユーザー tubo28tubo28
提出日時 2016-08-05 23:05:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,122 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 122,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 16:26:01
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 24 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 27 ms
5,376 KB
testcase_08 AC 21 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 18 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 30 ms
5,376 KB
testcase_13 AC 25 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 31 ms
5,376 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 AC 35 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 17 ms
5,376 KB
testcase_23 AC 34 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 25 ms
5,376 KB
testcase_26 AC 38 ms
5,376 KB
testcase_27 AC 25 ms
5,376 KB
testcase_28 AC 19 ms
5,376 KB
testcase_29 AC 20 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(cur,k) for (int cur = 0; cur < (int)(k); cur++)
#define all(cnt) begin(cnt), end(cnt)

const int INF = 1e9;

int n, m;
vector<vector<int>> g;
vector<int> dist, mi, ma;

int main() {
    while (cin >> n >> m) {
        g.assign(n, {});
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            g[a].emplace_back(b);
            g[b].emplace_back(a);
        }
        queue<int> q;
        q.push(0);
        dist.assign(n, INF);
        dist[0] = 0;
        while (q.size()) {
            int cur = q.front();
            q.pop();
            for (auto &dst : g[cur]) {
                if (dist[dst] == INF) {
                    q.push(dst);
                    dist[dst] = dist[cur] + 1;
                }
            }
        }
        mi.assign(n, INF);
        ma.assign(n, -INF);
        for (int i = 0; i < n; i++) {
            for (auto j : g[i]) {
                if (dist[j] == 1) {
                    mi[i] = min(mi[i], j);
                    ma[i] = max(ma[i], j);
                }
            }
        }
        bool ok = false;
        for (int i = 0; i < n; i++) {
            for (auto &j : g[i]) {
                if (mi[i] != ma[j] && mi[i] != INF && ma[j] != -INF) ok = true;
                if (mi[j] != ma[i] && mi[j] != INF && ma[i] != -INF) ok = true;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
}
0