結果

問題 No.1340 おーじ君をさがせ
ユーザー pyonthpyonth
提出日時 2021-02-27 02:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 206,512 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-07-25 23:53:33
合計ジャッジ時間 5,966 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 27 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 10 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 44 ms
4,380 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 77 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 18 ms
4,380 KB
testcase_31 AC 77 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 77 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 19 ms
4,380 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr int inf = 1e9 + 10;
constexpr ll INF = (ll)4e18 + 10;
constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
template <typename T>
inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T>
inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
vector<vector<ll>> product(const vector<vector<ll>> &a, const vector<vector<ll>> &b) {
    assert(a[0].size() == b.size());
    vector<vector<ll>> c(a.size(), vector<ll>(b[0].size()));
    rep(i, (int)a.size()) rep(k, (int)b.size()) rep(j, (int)b[0].size()) {
        c[i][j] = c[i][j] | (a[i][k] & b[k][j]);
    }
    return c;
}
vector<vector<ll>> powmat(vector<vector<ll>> a, ll n) {
    vector<vector<ll>> b(a.size(), vector<ll>(a.size()));
    rep(i, (int)a.size()) b[i][i] = 1;
    while (n > 0) {
        if (n & 1) b = product(b, a);
        a = product(a, a);
        n >>= 1;
    }
    return b;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(n));
    ll k;
    cin >> k;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        a[x][y] = 1;
    }
    vector<vector<ll>> ans = powmat(a, k);
    int x = 0;
    rep(i, n) {
        int y = 0;
        rep(j, n) y += ans[i][j];
        x += (y != 0);
    }
    cout << x << endl;
    return 0;
}
0