結果

問題 No.1749 ラムドスウイルスの感染拡大
ユーザー square1001square1001
提出日時 2021-11-19 21:29:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,006 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 73,808 KB
実行使用メモリ 27,356 KB
最終ジャッジ日時 2023-08-30 07:26:39
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
11,436 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using mint = modint<998244353>;
vector<vector<mint> > mul(int N, vector<vector<mint> > A, vector<vector<mint> > B) {
	vector<vector<mint> > C(N, vector<mint>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				C[i][k] += A[i][j] * B[j][k];
			}
		}
	}
	return C;
}
int main() {
	int N, M; long long T;
	cin >> N >> M >> T;
	vector<vector<mint> > A(N, vector<mint>(N));
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		A[a][b] += 1;
		A[b][a] += 1;
	}
	vector<vector<mint> > Z(N, vector<mint>(N));
	for (int i = 0; i < N; ++i) {
		Z[i][i] = 1;
	}
	while (T >= 1) {
		if (T % 2 == 1) {
			Z = mul(N, Z, A);
		}
		A = mul(N, A, A);
		T /= 2;
	}
	cout << Z[0][0].get() << endl;
	return 0;
}
0