結果

問題 No.1340 おーじ君をさがせ
ユーザー MisterMister
提出日時 2021-01-15 21:36:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,868 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 88,536 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-17 19:40:51
合計ジャッジ時間 6,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 34 ms
4,376 KB
testcase_14 AC 94 ms
4,376 KB
testcase_15 AC 79 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 27 ms
4,380 KB
testcase_18 AC 47 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 126 ms
4,380 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 243 ms
4,380 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 9 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 51 ms
4,376 KB
testcase_31 AC 244 ms
4,376 KB
testcase_32 AC 228 ms
4,380 KB
testcase_33 AC 226 ms
4,376 KB
testcase_34 AC 204 ms
4,376 KB
testcase_35 AC 246 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 244 ms
4,376 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 1 ms
4,380 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 56 ms
4,376 KB
testcase_50 AC 57 ms
4,376 KB
testcase_51 AC 57 ms
4,380 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 2 ms
4,380 KB
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Number/matrix.hpp"

#include <vector>

template <class T>
struct Matrix : public std::vector<std::vector<T>> {
    // constructor
    using std::vector<std::vector<T>>::vector;

    Matrix(int h, int w, T val = 0) {
        this->resize(h);
        for (auto& v : *this) v.resize(w, val);
    }

    static Matrix id(int n) {
        Matrix m(n, n);
        for (int i = 0; i < n; ++i) m[i][i] = 1;
        return m;
    }

    // arithmetic
    Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
    Matrix& operator*=(const Matrix& m) {
        int h1 = this->size(),
            h2 = m.size(),
            w2 = m.front().size();

        Matrix nmat(h1, w2);
        for (int i = 0; i < h1; ++i) {
            for (int j = 0; j < w2; ++j) {
                for (int k = 0; k < h2; ++k) {
                    nmat[i][j] += (*this)[i][k] * m[k][j];
                }
            }
        }
        return *this = nmat;
    }

    template <class U>
    Matrix pow(U k) {
        Matrix ret = id(this->size());
        Matrix a = *this;

        while (k > 0) {
            if (k & 1) ret *= a;
            a *= a;
            k >>= 1;
        }
        return ret;
    }
};
#line 2 "main.cpp"
#include <atcoder/modint>
#include <iostream>
#line 5 "main.cpp"

using namespace std;
using lint = long long;
using mint = atcoder::static_modint<1000000009>;

void solve() {
    int n, m;
    lint t;
    cin >> n >> m >> t;

    Matrix<mint> mat(n, n, 0);
    while (m--) {
        int u, v;
        cin >> u >> v;
        mat[u][v] = 1;
    }
    mat = mat.pow(t);

    int ans = 0;
    for (int v = 0; v < n; ++v) {
        if (mat[v][0] != 0) ++ans;
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0