結果

問題 No.408 五輪ピック
ユーザー eitahoeitaho
提出日時 2016-08-08 00:19:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,130 ms / 5,000 ms
コード長 2,160 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 87,544 KB
実行使用メモリ 52,864 KB
最終ジャッジ日時 2024-04-25 00:40:53
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 16 ms
6,016 KB
testcase_06 AC 43 ms
50,688 KB
testcase_07 AC 40 ms
41,856 KB
testcase_08 AC 16 ms
9,856 KB
testcase_09 AC 22 ms
17,920 KB
testcase_10 AC 34 ms
34,816 KB
testcase_11 AC 30 ms
30,464 KB
testcase_12 AC 48 ms
36,992 KB
testcase_13 AC 16 ms
6,784 KB
testcase_14 AC 16 ms
17,920 KB
testcase_15 AC 16 ms
5,376 KB
testcase_16 AC 20 ms
8,704 KB
testcase_17 AC 27 ms
14,848 KB
testcase_18 AC 35 ms
23,552 KB
testcase_19 AC 41 ms
34,432 KB
testcase_20 AC 25 ms
31,872 KB
testcase_21 AC 14 ms
19,840 KB
testcase_22 AC 41 ms
51,200 KB
testcase_23 AC 51 ms
52,608 KB
testcase_24 AC 717 ms
52,480 KB
testcase_25 AC 23 ms
5,632 KB
testcase_26 AC 57 ms
52,864 KB
testcase_27 AC 3,130 ms
5,376 KB
testcase_28 AC 27 ms
28,032 KB
testcase_29 AC 26 ms
28,032 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:69:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>
#include <bitset>
#include <emmintrin.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }

const int MaxN = 20000;
const int MaxM = 50000;
int N, M;
ll Adj[MaxN][(MaxN + 63) / 64];
Pii E[MaxM];

void solve() {
    rep(ea, M) {
        int a = E[ea].first, b = E[ea].second;
        bool adjA = Adj[0][a >> 6] >> (a & 63) & 1;
        bool adjB = Adj[0][b >> 6] >> (b & 63) & 1;
        if (!adjA && !adjB) continue;
        ll eb = lower_bound(E + ea + 1, E + M, Pii(a + 1, 0)) - E;
        for (; eb < M; eb++) if (E[eb].first != b && E[eb].second != b) {
            int c = E[eb].first, d = E[eb].second;
            if (Adj[0][c >> 6] >> (c & 63) & 1) {
                if (adjA && Adj[b][d >> 6] >> (d & 63) & 1 || adjB && Adj[a][d >> 6] >> (d & 63) & 1) {
                    cout << "YES\n";
                    return;
                }
            }
            if (Adj[0][d >> 6] >> (d & 63) & 1) {
                if (adjA && Adj[b][c >> 6] >> (c & 63) & 1 || adjB && Adj[a][c >> 6] >> (c & 63) & 1) {
                    cout << "YES\n";
                    return;
                }
            }
        }
    }
    cout << "NO\n";
}

int main() {
    scanf("%d %d", &N, &M);
    int mi = 0;
    rep(i, M) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        Adj[a][b >> 6] |= 1LL << (b & 63);
        Adj[b][a >> 6] |= 1LL << (a & 63);
        if (a > b) swap(a, b);
        if (a != 0) E[mi++] = Pii(a, b);
    }
    M = mi;
    sort(E, E + M);
    solve();
    return 0;
}
0