結果

問題 No.1340 おーじ君をさがせ
ユーザー shinchanshinchan
提出日時 2021-01-16 04:16:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,752 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 207,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 01:05:53
合計ジャッジ時間 6,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;



///////Matrix
template<class T> struct Matrix {
    vector<vector<T> > val;
    // 縦, 横, 初期値
    Matrix(int n = 1, int m = 1, T v = 0) : val(n, vector<T>(m, v)) {}
    void init(int n, int m, T v = 0) {val.assign(n, vector<T>(m, v));}
    Matrix<T>& operator = (const Matrix<T> &A) {
        val = A.val; return *this;
    }
    size_t size() const {return val.size();}
    vector<T>& operator [] (int i) {return val[i];}
    const vector<T>& operator [] (int i) const {return val[i];}
    friend ostream& operator << (ostream& s, const Matrix<T>& M) {
        s << endl;
        for (int i = 0; i < (int)M.size(); ++i) s << M[i] << endl;
        return s;
    }
};

template<class T> Matrix<T> operator * (const Matrix<T> &A, const Matrix<T> &B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < B[0].size(); ++j)
            for (int k = 0; k < B.size(); ++k)
                R[i][j] += A[i][k] * B[k][j];
    return R;
}

template<class T> Matrix<T> pow(const Matrix<T> &A, long long n) {
    Matrix<T> R(A.size(), A.size());
    auto B = A;
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) {
        if (n & 1) R = R * B;
        B = B * B;
        n >>= 1;
    }
    return R;
}

template<class T> vector<T> operator * (const Matrix<T> &A, const vector<T> &B) {
    vector<T> v(A.size());
    for (int i = 0; i < A.size(); ++i)
        for (int k = 0; k < B.size(); ++k)
            v[i] += A[i][k] * B[k];
    return v;
}

template<class T> Matrix<T> operator + (const Matrix<T> &A, const Matrix<T> &B) {
    Matrix<T> R(A.size(), A[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < A[0].size(); ++j)
            R[i][j] = A[i][j] + B[i][j];
    return R;
}

template<class T> Matrix<T> operator - (const Matrix<T> &A, const Matrix<T> &B) {
    Matrix<T> R(A.size(), A[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < A[0].size(); ++j)
            R[i][j] = A[i][j] - B[i][j];
    return R;
}



int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, t;
    cin >> n >> m >> t;
    Matrix<ll> mat(n, n, 0);
    int a, b;
    for(int i=0;i<m;i++){
        cin >> a >> b;
        mat[b][a] = 1;
    }
    
    mat = pow(mat, t);
    int ans = 0;
    for(int i=0;i<n;i++){
        if(mat[i][0]) ans++;
    }
    cout << ans << endl;
    return 0;
}


0