結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー sapphire__15sapphire__15
提出日時 2021-11-19 21:34:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 9,215 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 139,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 07:36:41
合計ジャッジ時間 5,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 46 ms
4,376 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 AC 45 ms
4,376 KB
testcase_11 AC 35 ms
4,376 KB
testcase_12 AC 49 ms
4,376 KB
testcase_13 AC 46 ms
4,380 KB
testcase_14 AC 236 ms
4,380 KB
testcase_15 AC 242 ms
4,376 KB
testcase_16 AC 246 ms
4,376 KB
testcase_17 AC 246 ms
4,384 KB
testcase_18 AC 255 ms
4,380 KB
testcase_19 AC 245 ms
4,380 KB
testcase_20 AC 169 ms
4,376 KB
testcase_21 AC 192 ms
4,376 KB
testcase_22 AC 34 ms
4,376 KB
testcase_23 AC 232 ms
4,380 KB
testcase_24 AC 27 ms
4,380 KB
testcase_25 AC 64 ms
4,380 KB
testcase_26 AC 21 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 34 ms
4,380 KB
testcase_31 AC 31 ms
4,380 KB
testcase_32 AC 31 ms
4,380 KB
testcase_33 AC 31 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <complex>
#include <bitset>
#include <iomanip>
#include <memory>
#include <chrono>
#include <functional>

#define rep(i, n, s) for(int i = (s); i < int(n); i++)
#define per(i, n, s) for(int i = (n - 1); i >= int(s); i--)
#define MM << " " <<
#define all(x) x.begin(), x.end()
#define rall(x) rbegin(x), rend(x)

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using MaxHeap = std::priority_queue<T>;

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
using Pdd = std::pair<double, double>;

template <class T>
bool chmin(T &a, const T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
bool chmax(T &a, const T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void vdeb(const std::vector<T> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
        if (i == n - 1)
            std::cout << da[i];
        else
            std::cout << da[i] << " ";
    }
    std::cout << std::endl;
}
template<class T>
void vdeb(const std::vector<std::vector<T>> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
        std::cout << i << " : ";
        vdeb(da[i]);
    }
    std::cout << std::endl;
}

template <>
void vdeb(const std::vector<std::string> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) { std::cout << da[i] << std::endl; }
}

struct modint {
    long long num;
    const static long long p = 998244353;
    constexpr static long long pow(long long n, long long k) {//n^k(mod p)
        long long ret = 1;
        while(k) {
            if(k&1) ret = ret * n % p;
            n = n * n % p;
            k >>= 1;
        }
        return ret;
    }
    // a*A + b*B = 1
    constexpr static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1
        if (a == 1) {
            a = 1;
        }
        else {
            long long A = b, B = a % b;
            euclid(A, B);
            b = (A - (p + a / b) % p * B % p + p) % p;
            a = B;
        }
    }
    constexpr static long long rev(const long long n) {// n*x-p*y=1
        //long long q = p;
        //euclid(p, n, p);
        //return n % q;
        return pow(n,p-2);
    }
    constexpr modint() : num(0) {}
    constexpr modint(long long x) : num(x%p < 0 ? x%p+p : x%p) {}
    constexpr modint inv() const {return rev(num);}
    modint operator-() const {return modint(p-num);}
    modint& operator+=(const modint &other){
        num = (num + other.num) % p;
        return *this;
    }
    modint& operator-=(const modint &other){
        num = (num - other.num + p) % p;
        return *this;
    }
    modint& operator*=(const modint &other){
        num = (num * other.num) % p;
        return *this;
    }
    modint& operator/=(const modint &other){
        (*this) *= other.inv();
        return *this;
    }
    modint& operator+=(const long long &other){
        num = (num + other) % p;
        return *this;
    }
    modint& operator-=(const long long &other){
        num = (num - other + p) % p;
        return *this;
    }
    modint& operator*=(const long long &other){
        num = (num * other) % p;
        return *this;
    }
    modint& operator/=(const long long &other){
        (*this) *= rev(other);
        return *this;
    }
    modint& operator++(){return *this += 1;}
    modint& operator--(){return *this -= 1;}
    modint& operator=(const long long &other){return (*this) = modint(other);}
    modint operator+(const modint &other) const{return modint(*this) += other;}
    modint operator-(const modint &other) const{return modint(*this) -= other;}
    modint operator*(const modint &other) const{return modint(*this) *= other;}
    modint operator/(const modint &other) const{return modint(*this) /= other;}
    modint operator+(const long long &other) const{return modint(*this) += other;}
    modint operator-(const long long &other) const{return modint(*this) -= other;}
    modint operator*(const long long &other) const{return modint(*this) *= other;}
    modint operator/(const long long &other) const{return modint(*this) /= other;}
    bool operator==(const modint &other) const{return num == other.num;}
};
std::istream& operator>>(std::istream &is, modint x) {
    is >> x.num;
    return is;
}
std::ostream& operator<<(std::ostream &os, const modint &x){
    os << x.num;
    return os;
}


template<class T>
class Matrix {
    T* table;
    size_t colomn_, row_;

    struct Plus {
        static T apply(const T &l, const T &r) {
            return l + r;
        }
    };
    struct Minus {
        static T apply(const T &l, const T &r) {
            return l - r;
        }
    };
    template<class L, class R, class Op>
    class Expression {
        const L& l_;
        const R& r_;
        public:
        Expression(L& l, const R& r) : l_(l), r_(r) {}
        T at(size_t i, size_t j) const {
            return Op::apply(l_.at(i, j), r_.at(i, j));
        }
        size_t colomn() const { return l_.colomn(); }
        size_t row() const { return l_.row(); }
    };
    T* reserve_memory() {
        T* ret = new T[colomn_*row_];
        for(size_t i = 0; i < colomn_*row_; i++) ret[i] = T();
        return ret;
    }
    void delete_memory(T* p) {
        delete[] p;
    }

    public:
    Matrix (const size_t colomn, const size_t row) : colomn_(colomn), row_(row) {
        table = reserve_memory();
    }
    Matrix(const size_t size) : Matrix(size, size) {}
    Matrix(const std::vector<std::vector<T>> &_ihs) : Matrix(_ihs.size(), _ihs[0].size()) {
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                at(i, j) = _ihs[i][j];
            }
        }
    }
    Matrix(const Matrix &rhs) : Matrix(rhs.colomn(), rhs.row()) {
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                at(i, j) = rhs.at(i, j);
            }
        }
    }
    ~Matrix() {
        delete_memory(table);
    }
    template<class L, class R>
    Expression<L, Plus, R> operator+(const R& rhs) const {
        assert(colomn() == rhs.colomn() && row() == rhs.row());
        return Expression<L, Plus, R>(*this, rhs);
    }
    template<class L, class R>
    Expression<L, R, Minus> operator-(const R& rhs) const {
        assert(colomn() == rhs.colomn() && row() == rhs.row());
        return Expression<L, R, Minus>(*this, rhs);
    }
    template<class E>
    Matrix operator*(const E& rhs) const {
        return Matrix(*this)*=rhs;
    }
    template<class E>
    Matrix& operator*=(const E& rhs) {
        assert(row() == rhs.colomn());
        T* tmp_p = reserve_memory();
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                for(size_t k = 0; k < colomn_; k++) {
                    tmp_p[i*row_+k] += at(i, j) * rhs.at(j, k);
                }
            }
        }
        delete_memory(table);
        table = tmp_p;
        return *this;
    }
    template<class E>
    Matrix& operator=(const E& rhs) {
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                at(i, j) = rhs.at(i, j);
            }
        }
        return *this;
    }
    Matrix& operator=(const Matrix<T>& rhs) {
        if(this == &rhs) return *this;
        row_ = rhs.row(); colomn_ = rhs.colomn();
        T* tmp_p = reserve_memory();
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                tmp_p[i*row_+j] = rhs.at(i, j);
            }
        }
        delete_memory(table);
        table = tmp_p;
        return *this;
    }
    size_t colomn() const {return colomn_;}
    size_t row() const {return row_;}
    T& at(size_t i, size_t j) { return table[i*row_+j]; }
    T at(size_t i, size_t j) const { return table[i*row_+j]; }
    void output() const {
        for(size_t i = 0; i < colomn_; i++) {
            for(size_t j = 0; j < row_; j++) {
                if(j == row_-1) std::cout << at(i,j) << '\n';
                else std::cout << at(i, j) << " ";
            }
        }
    }
    Matrix e() const {
        assert(row() == colomn());
        Matrix ret(row());
        for(size_t i = 0; i < row(); i++) {
            ret.at(i, i) += 1;
        }
        return ret;
    }
};

template<class T>
Matrix<T> power(Matrix<T> &da, int64_t k) {
    Matrix<T> ret = da.e();
    while(k) {
        if(k&1) ret *= da;
        da = da*da;
        k >>= 1;
    }
    return ret;
}

using namespace std;

int main() {
    ll n, m, t; cin >> n >> m >> t;
    Matrix<modint> da(n);
    rep(i,m,0) {
        int a, b; cin >> a >> b;
        da.at(a, b) += 1;
        da.at(b, a) += 1;
    }
    auto ans = power(da, t);
    cout << ans.at(0, 0) << endl;
}
0