結果

問題 No.408 五輪ピック
ユーザー fine
提出日時 2016-08-05 23:49:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 832 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 173,336 KB
実行使用メモリ 53,120 KB
最終ジャッジ日時 2024-11-07 04:46:24
合計ジャッジ時間 26,231 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef vector<bool> vec;
typedef vector<vec> mat;

mat A;
vec x;

vec mul(const mat& A, const vec& x) {
    int s = x.size();
    vec ret(s, false);
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            ret[i] = (A[i][j] & x[j]) | ret[i];
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    A = mat(n, vec(n, false));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[a][b] = true;
        A[b][a] = true;
    }
    x = vec(n);
    for (int i = 0; i < n; i++) x[i] = A[0][i];
    for (int i = 0; i < 4; i++) {
        x = mul(A, x);
    }
    if (x[0]) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}
0