結果

問題 No.1340 おーじ君をさがせ
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-24 23:39:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 3,324 bytes
コンパイル時間 2,744 ms
コンパイル使用メモリ 205,400 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 23:39:07
合計ジャッジ時間 6,083 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll modc = 998244353;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(modc-2);}
    mint& operator/=(const mint& a){ return (*this) *= a.inv();}
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{ return x == a.x;}
    bool operator != (const mint& a) const{ return x != a.x;}
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint &m) {
        ll t;
        ip >> t;
        m = mint(t);
        return ip;
    }
    ll val(){ return x;}
};

template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
void show(matrix<T> &a){
    for (int i=0; i<a.size(); i++){
        for (int j=0; j<a[i].size(); j++) cout << a[i][j] << " ";
        cout << endl;
    }
}

template<typename T>
matrix<T> dot(matrix<T> &a, matrix<T> &b){
    int N = a.size();
    matrix<T> c(N, vector<T>(N));
    for (int i=0; i<N; i++){
        for (int k=0; k<N; k++){
            for (int j=0; j<N; j++) c[i][j] |= a[i][k] & b[k][j];
        }
    }
    return c;
}

template<typename T>
T det(matrix<T> a){
    int N = a.size();
    T res = 1;
    for (int i=0; i<N; i++){
        if (a[i][i] == 0){
            for (int j=i+1; j<N; j++){
                if (a[i][j] != 0){
                    swap(a[i], a[j]);
                    res *= -1;
                    break;
                }
            }
            if (a[i][i] == 0) return 0;
        }
        res *= a[i][i];
        T iv = (T) 1 / a[i][i];
        for (int k=i; k<N; k++) a[i][k] *= iv;
        for (int j=i+1; j<N; j++){
            T mag = a[j][i];
            for (int k=i; k<N; k++){
                a[j][k] -= mag * a[i][k];
            }
        }
    }

    return res;
}

template<typename T>
matrix<T> pow(matrix<T> a, ll N){
    int M = a.size();
    matrix<T> b(M, vector<T>(M));
    for (int i=0; i<M; i++) b[i][i] = 1;
    while(N){
        if (N % 2 == 1) b = dot(b, a);
        N >>= 1;
        a = dot(a, a);
    }
    return b;
}

int main(){

    ll N, M, T, a, b, ans=0;
    cin >> N >> M >> T;
    matrix<ll> G(N, vector<ll>(N));
    for (int i=0; i<M; i++){
         cin >> a >> b;
         G[b][a] = 1;
    }

    G = pow(G, T);

    for (int i=0; i<N; i++) ans += G[i][0];
    cout << ans << endl;

    return 0;
}
0