結果
問題 | No.1749 ラムドスウイルスの感染拡大 |
ユーザー | stoq |
提出日時 | 2021-11-19 22:23:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 9,253 bytes |
コンパイル時間 | 4,137 ms |
コンパイル使用メモリ | 276,864 KB |
実行使用メモリ | 28,064 KB |
最終ジャッジ日時 | 2024-06-10 09:31:15 |
合計ジャッジ時間 | 7,832 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
16,156 KB |
testcase_01 | AC | 15 ms
9,088 KB |
testcase_02 | AC | 15 ms
9,216 KB |
testcase_03 | AC | 14 ms
9,216 KB |
testcase_04 | AC | 90 ms
9,088 KB |
testcase_05 | AC | 16 ms
9,088 KB |
testcase_06 | AC | 15 ms
9,216 KB |
testcase_07 | AC | 16 ms
9,216 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 | -- | - |
ソースコード
#define MOD_TYPE 2 #include <bits/stdc++.h> using namespace std; #include <atcoder/all> //#include <atcoder/modint> //#include <atcoder/lazysegtree> using namespace atcoder; #if 0 #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 0 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tag_and_trait.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace __gnu_pbds; using namespace __gnu_cxx; template <typename T> using extset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #endif #if 0 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #pragma region Macros using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; #if MOD_TYPE == 1 constexpr ll MOD = ll(1e9 + 7); #else #if MOD_TYPE == 2 constexpr ll MOD = 998244353; #else constexpr ll MOD = 1000003; #endif #endif using mint = static_modint<MOD>; constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr double PI = acos(-1.0); constexpr double EPS = 1e-11; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; #define UNIQUE(v) v.erase(unique(all(v)), v.end()) struct io_init { io_init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T& val) { fill((T*)array, (T*)(array + N), val); } template <typename T> vector<T> compress(vector<T>& v) { vector<T> val = v; sort(all(val)), val.erase(unique(all(val)), val.end()); for (auto&& vi : v) vi = lower_bound(all(val), vi) - val.begin(); return val; } template <typename T, typename U> constexpr istream& operator>>(istream& is, pair<T, U>& p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream& operator<<(ostream& os, pair<T, U> p) noexcept { os << p.first << " " << p.second; return os; } ostream& operator<<(ostream& os, mint m) { os << m.val(); return os; } ostream& operator<<(ostream& os, modint m) { os << m.val(); return os; } template <typename T> constexpr istream& operator>>(istream& is, vector<T>& v) noexcept { for (int i = 0; i < v.size(); i++) is >> v[i]; return is; } template <typename T> constexpr ostream& operator<<(ostream& os, vector<T>& v) noexcept { for (int i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : " "); return os; } random_device seed_gen; mt19937_64 engine(seed_gen()); struct BiCoef { vector<mint> fact_, inv_, finv_; BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); for (int i = 2; i < n; i++) { fact_[i] = fact_[i - 1] * i; inv_[i] = -inv_[MOD % i] * (MOD / i); finv_[i] = finv_[i - 1] * inv_[i]; } } mint C(ll n, ll k) const noexcept { if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n - k]; } mint P(ll n, ll k) const noexcept { return C(n, k) * fact_[k]; } mint H(ll n, ll k) const noexcept { return C(n + k - 1, k); } mint Ch1(ll n, ll k) const noexcept { if (n < 0 || k < 0) return 0; mint res = 0; for (int i = 0; i < n; i++) res += C(n, i) * mint(n - i).pow(k) * (i & 1 ? -1 : 1); return res; } mint fact(ll n) const noexcept { if (n < 0) return 0; return fact_[n]; } mint inv(ll n) const noexcept { if (n < 0) return 0; return inv_[n]; } mint finv(ll n) const noexcept { if (n < 0) return 0; return finv_[n]; } }; BiCoef bc(500010); #pragma endregion // ------------------------------- #pragma region Matrix // 参考・引用:https://qiita.com/gnbrganchan/items/47118d45b3af9d5ae9a4 using Type = mint; struct Matrix { // 行列A vector<vector<Type>> A; // コンストラクタ:第1引数⇒行数、第2引数⇒列数、第3引数⇒初期値 Matrix() : A() {} Matrix(int h, int w) : A(vector<vector<Type>>(h, vector<Type>(w))) {} Matrix(int h, int w, Type d) : A(vector<vector<Type>>(h, vector<Type>(w, d))) {} Matrix(vector<vector<Type>> A) : A(A) {} Matrix(initializer_list<initializer_list<Type>> A) : A(A.begin(), A.end()) {} // 添え字アクセス vector<Type> operator[](const int i) const { return A[i]; } vector<Type>& operator[](const int i) { return A[i]; } // 行数・列数 int r = A.size(); int c = (A.empty() ? 0 : A[0].size()); // 行列同士の演算 Matrix& operator+=(const Matrix& B) { assert(c == B.c && r == B.r); rep(i, r) rep(j, c) A[i][j] += B[i][j]; return *this; } Matrix& operator-=(const Matrix& B) { assert(c == B.c && r == B.r); rep(i, r) rep(j, c) A[i][j] -= B[i][j]; return *this; } Matrix& operator*=(const Matrix& B) { if (B.r == 1 and B.c == 1) { return (*this) *= B[0][0]; } else if (r == 1 and c == 1) { Type k = A[0][0]; (*this) = B; return (*this) *= k; } assert(c == B.r); Matrix m2(r, B.c, 0); rep(i, r) rep(j, B.c) rep(k, c) m2[i][j] += A[i][k] * B[k][j]; c = B.c; rep(i, r) A[i].resize(c); rep(i, r) rep(j, c) A[i][j] = m2[i][j]; return *this; } Matrix operator+(const Matrix& B) const { return Matrix(*this) += B; } Matrix operator-(const Matrix& B) const { return Matrix(*this) -= B; } Matrix operator*(const Matrix& B) const { return Matrix(*this) *= B; } vector<Type> operator*(const vector<Type>& b) const { assert(c == b.size()); vector<Type> res(r); rep(i, r) rep(k, c) res[i] += A[i][k] * b[k]; return res; } bool operator==(const Matrix& B) { assert(c == B.c && r == B.r); bool flg = true; rep(i, r) rep(j, c) if (A[i][j] != B[i][j]) flg = false; return flg; } // 行列とスカラの演算 Matrix& operator+=(const Type& k) { rep(i, r) rep(j, c) A[i][j] += k; return *this; } Matrix& operator-=(const Type& k) { rep(i, r) rep(j, c) A[i][j] -= k; return *this; } Matrix& operator*=(const Type& k) { rep(i, r) rep(j, c) A[i][j] *= k; return *this; } Matrix& operator/=(const Type& k) { rep(i, r) rep(j, c) A[i][j] /= k; return *this; } Matrix operator+(const Type& k) const { return Matrix(*this) += k; } Matrix operator-(const Type& k) const { return Matrix(*this) -= k; } Matrix operator*(const Type& k) const { return Matrix(*this) *= k; } Matrix operator/(const Type& k) const { return Matrix(*this) /= k; } Matrix operator-() const { return Matrix(*this) *= -1; } // 回転(degの数だけ時計回りに90度回転) Matrix& rot(int deg) { Matrix m2(c, r); if (deg == 1 || deg == 3) { if (deg == 1) rep(i, r) rep(j, c) m2[j][r - i - 1] = A[i][j]; if (deg == 3) rep(i, r) rep(j, c) m2[c - j - 1][i] = A[i][j]; swap(c, r); // 列数と行数を入れ替える A.resize(r); rep(i, r) A[i].resize(c); //リサイズ } if (deg == 2) rep(i, r) rep(j, c) m2[r - i - 1][c - j - 1] = A[i][j]; rep(i, r) rep(j, c) A[i][j] = m2[i][j]; return *this; } // 転置 Matrix& tran() { Matrix m2(c, r); rep(i, r) rep(j, c) m2[j][i] = A[i][j]; (*this) = m2; return *this; } // 単位行列 static Matrix E(int n) { Matrix res(n, n); rep(i, n) rep(j, n) res[i][j] = i == j; return res; } // 累乗 void pow(ll n) { assert(n >= 0); Matrix P = (*this); (*this) = E(r); while (n > 0) { if (n & 1) (*this) *= P; P *= P; n >>= 1; } } }; // 出力 ostream& operator<<(ostream& os, Matrix A) noexcept { rep(i, A.r) { if (i > 0) cout << "\n"; rep(j, A.c) { cout << A[i][j] << (j + 1 == A.c ? "" : " "); } } return os; } #pragma endregion void solve() { int n, m; ll t; cin >> n >> m >> t; Matrix A(n, n); rep(i, m) { int a, b; cin >> a >> b; A[a][b] = A[b][a] = 1; } vector<mint> b(n, 0); b[0] = 1; A.pow(t); b = A * b; cout << b[0] << "\n"; } int main() { solve(); }