結果

問題 No.1340 おーじ君をさがせ
ユーザー shinchanshinchan
提出日時 2021-01-16 01:06:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 199,004 KB
最終ジャッジ日時 2025-01-17 21:05:34
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
vector<vector<int> > mul(vector<vector<int> > a, vector<vector<int> > b){
    vector<vector<int> > ret(n, vector<int> (n, 0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int num = 0;
            for(int k=0;k<n;k++){
                num |= a[i][k] & b[k][j];
            }
            ret[i][j] = num;
        }
    } 
    return ret;
}

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

    return 0;
}
0