結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー popofypopofy
提出日時 2021-11-19 23:27:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 8,283 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 208,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 10:45:40
合計ジャッジ時間 7,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 60 ms
4,380 KB
testcase_09 AC 61 ms
4,376 KB
testcase_10 AC 60 ms
4,380 KB
testcase_11 AC 45 ms
4,376 KB
testcase_12 AC 64 ms
4,380 KB
testcase_13 AC 61 ms
4,376 KB
testcase_14 AC 313 ms
4,376 KB
testcase_15 AC 321 ms
4,376 KB
testcase_16 AC 324 ms
4,376 KB
testcase_17 AC 327 ms
4,380 KB
testcase_18 AC 337 ms
4,376 KB
testcase_19 AC 323 ms
4,376 KB
testcase_20 AC 216 ms
4,376 KB
testcase_21 AC 254 ms
4,376 KB
testcase_22 AC 43 ms
4,376 KB
testcase_23 AC 305 ms
4,376 KB
testcase_24 AC 34 ms
4,380 KB
testcase_25 AC 83 ms
4,380 KB
testcase_26 AC 29 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 43 ms
4,376 KB
testcase_31 AC 40 ms
4,380 KB
testcase_32 AC 40 ms
4,380 KB
testcase_33 AC 39 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define overload4(a, b, c, d, e, ...) e
#define rep1(a)          for(decltype(a) i = 0, i##_len = (a); i < i##_len; ++i)
#define rep2(i, a)       for(decltype(a) i = 0, i##_len = (a); i < i##_len; ++i)
#define rep3(i, a, b)    for(decltype(b) i = (a), i##_len = (b); i < i##_len; ++i)
#define rep4(i, a, b, c) for(decltype(b) i = (a), i##_len = (b); i < i##_len; i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a)          for(decltype(a) i = (a); i--;)
#define rrep2(i, a)       for(decltype(a) i = (a); i--;)
#define rrep3(i, a, b)    for(decltype(a) i = (b), i##_len = (a); i-- > i##_len;)
#define rrep4(i, a, b, c) for(decltype(a) i = (a)+((b)-(a)-1)/(c)*(c), i##_len = (a); i >= i##_len; i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x)   ((int)(x).size())
#define yes(s)  cout << ((s)?"Yes":"No") << "\n";
#define bit(n)  (1LL << ((int)(n)))
#define get1bit(x,n) (((x) >> (int)(n)) & 1)
#ifdef __LOCAL
#define dump(...) cerr << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
using ll = long long; using ld = long double; template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; template<class T> using PQ = priority_queue<T,V<T>,greater<T>>;
template<class T> ostream &operator<<(ostream &os, const vector<T>& vec) {if (vec.empty()) return os << "{}";stringstream ss;os << "{";for (auto e : vec) ss << "," << e;os << ss.str().substr(1) << "}";return os;}
void dump_func(){cerr << endl;}
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail){cerr << head;if (sizeof...(Tail) > 0) cerr << ", ";dump_func(std::move(tail)...);}
template<class T> istream &operator>>(istream& is, complex<T>& v) {T x, y; is >> x >> y; v.real(x); v.imag(y); return is;}
template<class T> istream &operator>>(istream& is, V<T>& v) {for (auto&& e : v) is >> e;return is;}
template<class T, class U> istream &operator>>(istream& is, pair<T, U>& v) {is >> v.first >> v.second;return is;}
template<class T, size_t n> istream &operator>>(istream& is, array<T, n>& v) {for (auto&& e : v) is >> e;return is;}
template<class... A> void print_rest() {cout << "\n";}
template<class T, class... A> void print_rest(const T& first, const A&... rest) {cout << " " << first; print_rest(rest...);}
template<class T, class... A> void print(const T& first, const A&... rest) {cout << fixed << setprecision(16) << first; print_rest(rest...);}
template<class T, class... A> void printx(const T& first, const A&... rest) {cout << fixed << setprecision(16) << first; print_rest(rest...); exit(0);}
template<class T> inline string join(const T& v, string sep = " ") {if (v.size() == 0) return "" ;stringstream ss;for (auto&& e : v) ss << sep << e;return ss.str().substr(1);}
template<class T> V<T> make_vec(size_t n, T a) {return V<T>(n, a);}
template<class... Ts> auto make_vec(size_t n, Ts... ts) {return V<decltype(make_vec(ts...))>(n, make_vec(ts...));}
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;}
template<class T> inline int lower_index(V<T>&a , T x) {return distance(a.begin(), lower_bound(all(a), x));}
template<class T> inline int upper_index(V<T>&a , T x) {return distance(a.begin(), upper_bound(all(a), x));}
template<class T, class F> pair<T,T> binarysearch(T ng, T ok, T eps, F f, bool sign = false) {while(abs(ng-ok)>eps) {auto mid=ng+(ok-ng)/2;if(sign^f(mid)){ok = mid;}else{ng = mid;}}return {ng,ok};}
template<class T> constexpr T cdiv(T x, T y) {return (x+y-1)/y;}
template<class T> constexpr bool between(T a, T x, T b) {return (a <= x && x < b);}
template<class T> constexpr T pos1d(T y, T x, T h, T w) {assert(between(T(0),y,h));assert(between(T(0),x,w));return y*w + x;}
template<class T> constexpr pair<T,T> pos2d(T p, T h, T w) {T y = p/w, x = p - y*w;assert(between(T(0),y,h));assert(between(T(0),x,w));return {y, x};}
constexpr ll modpow(ll x, ll n, ll m = 1152921504606846976LL) {ll ret = 1;for(;n>0;x=(__int128)x*x%m,n>>=1) if(n&1)ret=(__int128)ret*x%m;return ret;}
constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60;

const ll MOD = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

template<class T>
struct Matrix {
  V<V<T>> A;
  Matrix() {}
  Matrix(int n, int m) : A(n, V<T>(m, 0)) {}
  Matrix(int n) : A(n, V<T>(n, 0)) {};
  int height() const {return (A.size());}
  int width() const {return (A[0].size());}
  inline const V<T> &operator[](int k) const {return (A.at(k));}
  inline V<T> &operator[](int k) {return (A.at(k));}
  static Matrix I(int n) { Matrix mat(n); rep(i,n) mat[i][i] = 1; return (mat); }
  Matrix &operator+=(const Matrix &B) {
    int n = height(), m = width();
    assert(n == B.height() && m == B.width());
    rep(i,n) rep(j,m) (*this)[i][j] += B[i][j];
    return (*this);
  }
  Matrix &operator-=(const Matrix &B) {
    int n = height(), m = width();
    assert(n == B.height() && m == B.width());
    rep(i,n) rep(j,m) (*this)[i][j] -= B[i][j];
    return (*this);
  }
  Matrix &operator*=(const Matrix &B) {
    int n = height(), m = B.width(), p = width();
    assert(p == B.height());
    V<V<T>> C(n, V<T>(m, 0));
    rep(i,n) rep(j,m) rep(k,p) C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);
    A.swap(C);
    return (*this);
  }
  Matrix &operator*=(const T &coef) {
    rep(i,height()) rep(j,width()) (*this)[i][j] *= coef;
    return (*this);
  }
  Matrix &operator^=(ll k) {
    Matrix B = Matrix::I(height());
    while(k > 0) {
      if(k & 1) B *= *this;
      *this *= *this;
      k >>= 1LL;
    }
    A.swap(B.A);
    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);}
  Matrix operator^(const ll k) const { return (Matrix(*this) ^= k);}
  friend ostream &operator<<(ostream &os, Matrix &p) {
    int n = p.height(), m = p.width();
    rep(i,n) {
      os << "["; rep(j,m) os << p[i][j] << (j + 1 == m ? "]\n" : ",");
    }
    return (os);
  }
  T determinant() {
    Matrix B(*this);
    assert(width() == height());
    T ret = 1;
    rep(i,width()) {
      int idx = -1;
      for(int j = i; j < width(); j++) if(B[j][i] != 0) idx = j;
      if(idx == -1) return (0);
      if(i != idx) {
        ret *= -1;
        swap(B[i], B[idx]);
      }
      ret *= B[i][i];
      T vv = B[i][i];
      rep(j,width()) B[i][j] /= vv;
      for(int j = i + 1; j < width(); j++) {
        T a = B[j][i];
        rep(k,width()) B[j][k] -= B[i][k] * a;
      }
    }
    return (ret);
  }
};

struct Solver {
  VV<int> G;
  void solve() {
    ll n, m, t; cin >> n >> m >> t;
    Matrix<mint> mat(n, n);
    rep(i,m) {
      int a, b; cin >> a >> b;
      mat[a][b] += 1;
      mat[b][a] += 1;
    }
    auto ans = mat ^ t;
    print(ans[0][0]);
  }
} solver;
signed main(void) {cin.tie(nullptr);ios::sync_with_stdio(false);dump("");solver.solve();return 0;}
0