結果
| 問題 |
No.1340 おーじ君をさがせ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 21:36:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| コンパイル時間 | 949 ms |
| コンパイル使用メモリ | 85,480 KB |
| 最終ジャッジ日時 | 2025-01-17 18:42:45 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 WA * 21 |
ソースコード
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Number/matrix.hpp"
#include <vector>
template <class T>
struct Matrix : public std::vector<std::vector<T>> {
// constructor
using std::vector<std::vector<T>>::vector;
Matrix(int h, int w, T val = 0) {
this->resize(h);
for (auto& v : *this) v.resize(w, val);
}
static Matrix id(int n) {
Matrix m(n, n);
for (int i = 0; i < n; ++i) m[i][i] = 1;
return m;
}
// arithmetic
Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
Matrix& operator*=(const Matrix& m) {
int h1 = this->size(),
h2 = m.size(),
w2 = m.front().size();
Matrix nmat(h1, w2);
for (int i = 0; i < h1; ++i) {
for (int j = 0; j < w2; ++j) {
for (int k = 0; k < h2; ++k) {
nmat[i][j] += (*this)[i][k] * m[k][j];
}
}
}
return *this = nmat;
}
template <class U>
Matrix pow(U k) {
Matrix ret = id(this->size());
Matrix a = *this;
while (k > 0) {
if (k & 1) ret *= a;
a *= a;
k >>= 1;
}
return ret;
}
};
#line 2 "main.cpp"
#include <atcoder/modint>
#include <iostream>
#line 5 "main.cpp"
using namespace std;
using lint = long long;
using mint = atcoder::static_modint<1000000009>;
void solve() {
int n, m;
lint t;
cin >> n >> m >> t;
Matrix<mint> mat(n, n, 0);
while (m--) {
int u, v;
cin >> u >> v;
mat[u][v] = 1;
}
mat = mat.pow(t);
int ans = 0;
for (int v = 0; v < n; ++v) {
if (mat[v][0] != 0) ++ans;
}
cout << ans << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}