結果

問題 No.1340 おーじ君をさがせ
ユーザー oteraotera
提出日時 2021-01-16 05:50:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,868 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 207,888 KB
実行使用メモリ 18,356 KB
最終ジャッジ日時 2023-08-18 16:53:25
合計ジャッジ時間 5,953 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 18 ms
6,740 KB
testcase_12 AC 5 ms
4,692 KB
testcase_13 AC 15 ms
6,512 KB
testcase_14 AC 35 ms
9,836 KB
testcase_15 AC 31 ms
8,804 KB
testcase_16 AC 4 ms
4,392 KB
testcase_17 AC 12 ms
5,684 KB
testcase_18 AC 19 ms
6,944 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 21 ms
8,156 KB
testcase_22 AC 52 ms
12,796 KB
testcase_23 AC 21 ms
8,188 KB
testcase_24 AC 90 ms
17,544 KB
testcase_25 AC 6 ms
4,472 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 7 ms
4,988 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 22 ms
8,528 KB
testcase_31 AC 91 ms
18,200 KB
testcase_32 AC 85 ms
17,024 KB
testcase_33 AC 83 ms
16,760 KB
testcase_34 AC 76 ms
16,460 KB
testcase_35 AC 91 ms
17,024 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 92 ms
18,356 KB
testcase_39 AC 25 ms
6,896 KB
testcase_40 AC 27 ms
6,716 KB
testcase_41 AC 26 ms
6,716 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 19 ms
5,844 KB
testcase_47 AC 20 ms
6,172 KB
testcase_48 AC 22 ms
6,392 KB
testcase_49 AC 22 ms
6,572 KB
testcase_50 AC 22 ms
6,812 KB
testcase_51 AC 23 ms
6,976 KB
testcase_52 AC 41 ms
10,100 KB
testcase_53 AC 40 ms
10,008 KB
testcase_54 AC 41 ms
10,148 KB
testcase_55 AC 31 ms
8,036 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 14 ms
4,880 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 14 ms
5,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<vector<int>> mul(vector<vector<int>> a, vector<vector<int>> b) {
    int sz = (int)a.size();
    vector<vector<int>> ret(sz, vector<int>(sz, 0));
    rep(i, sz) {
        rep(j, sz) {
            rep(k, sz) {
                ret[i][k] |= (a[i][j] & b[j][k]);
            }
        }
    }
    return ret;
}

vector<vector<int>> pw(vector<vector<int>> a, ll n) {
    int sz = (int)a.size();
    if(n == 0) {
        vector<vector<int>> ret(sz, vector<int>(sz, 0));
        rep(i, sz) {
            ret[i][i] = 1LL;
        }
        return ret;
    }
    vector<vector<int>> ret = pw(mul(a, a), n / 2);
    if(n & 1) ret = mul(ret, a);
    return ret;
}

void solve() {
    int n, m; ll t; cin >> n >> m >> t;
    vector<vector<int>> g(n, vector<int>());
    vector<vector<int>> d(n, vector<int>(n, 0));
    rep(i, m) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        d[a][b] = 1;
    }
    d = pw(d, t);
    int cnt = 0;
    rep(i, n) {
        if(d[0][i]) {
            cerr << i << endl;
            ++ cnt;
        }
    }
    cout << cnt << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}
0