結果

問題 No.1340 おーじ君をさがせ
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2021-01-15 22:08:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 3,646 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 132,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 16:37:02
合計ジャッジ時間 4,595 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

template <typename T>
struct mat {
    int h, w;
    std::vector< std::vector<T> > d;
    mat() {}
    mat(int h, int w, T v=T(0)): h(h), w(w), d(h, std::vector<T>(w, v)){}
    std::vector<T>& operator[] (int i) {return d[i];}
    const std::vector<T>& operator[] (int i) const { return d[i];}
    void fil(T v=T(0)) { for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j] = v;}
    void unit() { for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j] = T(i==j);}
    mat<T> operator+(const mat<T>& a) const { // same size
        mat<T> res(h,w);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                res[i][j] = d[i][j]+a[i][j];
            }
        }
        return res;
    }
    mat<T> operator-(const mat<T>& a) const { // same size
        mat<T> res(h,w);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                res[i][j] = d[i][j]-a[i][j];
            }
        }
        return res;
    }
    mat<T> operator*(const mat<T>& a) const { // w = a.h
        mat<T> res(h,a.w);
        for (int i = 0; i < h; i++) {
            for (int k = 0; k < w; k++) {
                for (int j = 0; j < a.w; j++) {
                    res[i][j] |= d[i][k]&a[k][j];
                }
            }
        }
        return res;
    }
    mat<T> power(ll a) { // h = w
        mat<T> ret(h, w), me = *this;
        ret.unit();
        while (a > 0) {
            if (a & 1) ret = ret * me;
            me = me * me;
            a >>= 1;
        }
        return ret;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, t; cin >> n >> m >> t;
    vvii edges(n, vii(n, 0));
    rep(i, m) {
        int a, b; cin >> a >> b;
        edges[a][b] = 1;
    }

    mat<int> mmm(n, n, 0);
    mmm.d = edges;
    mat<int> am = mmm.power(t);
    int ans = 0;
    rep(i, n) ans += am[0][i];
    cout << ans << '\n';
    return 0;
}
0