結果

問題 No.2832 Nana's Fickle Adventure
ユーザー coindarwcoindarw
提出日時 2024-08-02 23:30:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 9,060 bytes
コンパイル時間 5,638 ms
コンパイル使用メモリ 323,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-02 23:31:13
合計ジャッジ時間 13,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 94 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 190 ms
6,940 KB
testcase_04 AC 115 ms
6,944 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 26 ms
6,940 KB
testcase_09 AC 14 ms
6,940 KB
testcase_10 AC 28 ms
6,944 KB
testcase_11 AC 177 ms
6,940 KB
testcase_12 AC 186 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 424 ms
6,940 KB
testcase_19 AC 367 ms
6,944 KB
testcase_20 AC 403 ms
6,944 KB
testcase_21 AC 394 ms
6,940 KB
testcase_22 AC 309 ms
6,940 KB
testcase_23 AC 400 ms
6,940 KB
testcase_24 AC 354 ms
6,944 KB
testcase_25 AC 380 ms
6,940 KB
testcase_26 AC 389 ms
6,940 KB
testcase_27 AC 11 ms
6,940 KB
testcase_28 AC 22 ms
6,940 KB
testcase_29 AC 203 ms
6,944 KB
testcase_30 AC 299 ms
6,944 KB
testcase_31 AC 335 ms
6,944 KB
testcase_32 AC 110 ms
6,940 KB
testcase_33 AC 3 ms
6,944 KB
testcase_34 AC 6 ms
6,940 KB
testcase_35 AC 25 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 348 ms
6,944 KB
testcase_38 AC 4 ms
6,940 KB
testcase_39 AC 190 ms
6,944 KB
testcase_40 AC 106 ms
6,940 KB
testcase_41 AC 188 ms
6,944 KB
testcase_42 AC 205 ms
6,944 KB
testcase_43 AC 368 ms
6,940 KB
testcase_44 AC 11 ms
6,940 KB
testcase_45 AC 5 ms
6,940 KB
testcase_46 AC 10 ms
6,940 KB
testcase_47 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>

#include <atcoder/all>
#else
#include <mylibs/all.h>
#endif

using ll = long long;
using lll = __int128_t;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define length(v) ((int)(v).size())
constexpr int inf = 2'000'000'000;
constexpr ll linf = 4'000'000'000'000'000'000, M7 = 1'000'000'007, M9 = 998'244'353;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;

// clang-format off
using vint = vector<int>;using vvint = vector<vector<int>>;using vvvint = vector<vector<vector<int>>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;using vvvll = vector<vector<vector<ll>>>;
using vlll = vector<lll>;using vvlll = vector<vector<lll>>;using vvvlll = vector<vector<vector<lll>>>;
using vchar = vector<char>;using vvchar = vector<vector<char>>;using vvvchar = vector<vector<vector<char>>>;
using vstr = vector<string>;using vvstr = vector<vector<string>>;using vvvstr = vector<vector<vector<string>>>;
using vpi = vector<pair<int, int>>;using vvpi = vector<vector<pair<int, int>>>;using vvpint = vector<vector<pair<int, int>>>;
using vpl = vector<pair<ll, ll>>;using vvpl = vector<vector<pair<ll, ll>>>;using vvplint = vector<vector<pair<ll, int>>>;
using vbool = vector<bool>;using vvbool = vector<vector<bool>>;using vvvbool = vector<vector<vector<bool>>>;

#define Vec(type, ...) __make_vec<type>(__VA_ARGS__)
template <class T> vector<T> __make_vec(size_t a) {return vector<T>(a);}template <class T, class... Ts>
auto __make_vec(size_t a, Ts... ts) {return vector<decltype(__make_vec<T>(ts...))>(a, __make_vec<T>(ts...));}
#define VecI(init, type, ...) __make_vecI<type, init>(__VA_ARGS__)
template <class T, T init>vector<T> __make_vecI(size_t a) {return vector<T>(a, init);}
template <class T, T init, class... Ts>
auto __make_vecI(size_t a, Ts... ts) {return vector<decltype(__make_vecI<T, init>(ts...))>(a, __make_vecI<T, init>(ts...));}

template <typename T, typename U>inline ostream& operator<<(ostream& os, const pair<T, U>& p) noexcept {return os << p.first << " " << p.second;}
inline ostream& operator<<(ostream& os, const modint& m) noexcept { return os << m.val(); }
template <int M>inline ostream& operator<<(ostream& os, const static_modint<M>& m) noexcept { return os << m.val(); }

template <typename T> struct is_static_modint : std::false_type {}; template <int MOD> struct is_static_modint<static_modint<MOD>> : std::true_type {};
template <template <typename...> typename C, typename Number>concept MyContainer = std::is_same_v<C<Number>, std::vector<Number>> || std::is_same_v<C<Number>, std::deque<Number>> || std::is_same_v<C<Number>, std::set<Number>> || std::is_same_v<C<Number>, std::unordered_set<Number>> || std::is_same_v<C<Number>, std::unordered_multiset<Number>> || std::is_same_v<C<Number>, std::multiset<Number>>;
template <typename Number>concept MyNumber = std::is_same_v<Number, int> || std::is_same_v<Number, ll> || std::is_same_v<Number, char> || std::is_same_v<Number, modint> || is_static_modint<Number>::value;
template <template <typename...> typename C, typename Number>concept MyContainerNumber = MyContainer<C, Number> && MyNumber<Number>;
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>concept MyNestedContainerNumber = MyContainer<OutCon, InCon<Number>> && MyContainerNumber<InCon, Number>;
template <template <typename...> typename C, typename Number>requires MyContainerNumber<C, Number>std::ostream& operator<<(std::ostream& os, const C<Number>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << ' ' << *itr;}return os;}
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>requires MyNestedContainerNumber<OutCon, InCon, Number>std::ostream& operator<<(std::ostream& os, const OutCon<InCon<Number>>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << '\n' << *itr;}return os;}
template <typename T, typename U>istream& operator>>(istream& is, pair<T, U>& p) {return is >> p.first >> p.second;}
template <typename T>istream& operator>>(istream& is, vector<T>& v) {for (auto& e : v) is >> e;return is;}
void inp() {}
template <typename T, typename... Args>void inp(T& a, Args&... args) {cin >> a, inp(args...);}
template <typename T>void inp1(vector<T>& v, int offset = 1, int len = -1) {if (len == -1) len = int(v.size()) - offset;assert(offset >= 0 && len >= 0);for (int i = offset; i < offset + len; ++i) cin >> v[i];}
template <typename T>void oup(const T& a) {cout << a << "\n";}
template <typename T, typename... Args>void oup(const T& a, const Args&... args) {cout << a << " ", oup(args...);}

inline string YesNo(bool cond) { return cond ? "Yes" : "No"; }
inline auto add1(auto vec, ll offset = 1) {for (auto& e : vec) e += offset;return vec;}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>void debug_out(T t) {cerr << t << "\n";}
template <typename T, typename... Args>void debug_out(T t, Args... args) {cerr << t << ", ";debug_out(args...);}
#endif

#ifdef ONLINE_JUDGE
#define todo(...) static_assert(false)
#else
#define todo(...)
#endif
// clang-format on

const ll M = 998244353;
using mint = modint998244353;
typedef vector<vector<mint>> Matrix;
typedef vector<mint> vec;

Matrix new_matrix(int n) {
    Matrix res(n, vec(n));
    return res;
}
Matrix new_matrix(int n, int m) {
    Matrix res(n, vec(m));
    return res;
}
Matrix operator*(const Matrix& m1, const Matrix& m2) {
    assert(m1.at(0).size() == m2.size());
    size_t n = m1.size();
    size_t m = m2.at(0).size();
    size_t l = m2.size();
    Matrix res(n, vec(m));
    rep(i, n) rep(j, m) rep(k, l) { res.at(i).at(j) += m1.at(i).at(k) * m2.at(k).at(j); }
    return res;
}
vec operator*(const Matrix& m, const vec& v) {
    assert(m.at(0).size() == v.size());
    vec res(v.size());
    rep(i, v.size()) rep(j, m.at(0).size()) { res.at(i) += m.at(i).at(j) * v.at(j); }
    return res;
}
Matrix E(size_t n) {
    Matrix res(n, vec(n));
    rep(i, n) res.at(i).at(i) = 1;
    return res;
}
Matrix pow(const Matrix& a, long long n) {
    Matrix b = a;
    Matrix res = E(a.size());
    while (n > 0) {
        if (n & 1) res = res * b;
        b = b * b;
        n >>= 1ll;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    cin >> n >> m >> x;
    vvint M(n + 1, vint(n + 1));
    struct edge {
        int to;
        edge(int _to) : to(_to) {}
    };
    vector<vector<edge>> G(n + 1);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        M[a][b]++;
        G[a].push_back(b);
        if (a != b) M[b][a]++;
        if (a != b) G[b].push_back(a);
    }

    auto vert = [&](int i, int j) -> int { return i * (n + 1) + j; };
    Matrix mat = new_matrix((n + 1) * (n + 1));
    reps(i, n) {
        reps(j, n) {
            int idx = vert(i, j);
            int cnt = G[j].size();
            if (cnt == 0) {
                mat[vert(j, j)][idx] += 1;
                continue;
            }
            if (cnt == 1) {
                if (M[j][j] == 1) {  // 自己ループ
                    mat[vert(j, j)][idx] += 1;
                    debug(i, j, idx, vert(j, G[j][0].to));
                    continue;
                } else if (i != j) {
                    mat[vert(j, j)][idx] += 1;
                    debug(i, j, idx, vert(j, G[j][0].to));
                    continue;
                } else {
                    mat[vert(j, G[j][0].to)][idx] += 1;
                    debug(i, j, idx, vert(j, G[j][0].to));
                    continue;
                }
            }
            mint cntInv = mint(1) / mint(cnt - 1);
            reps(k, n) {
                if (M[j][k] == 0) continue;
                int nIdx = vert(j, k);
                if (i != k) {  // 前の頂点と次の頂点が違う場合は自由に選べる
                    mat[nIdx][idx] += (M[j][k] * cntInv);
                } else {  // 直前に通った道だけ使えない
                    mat[nIdx][idx] += ((M[j][k] - 1) * cntInv);
                }
                debug(i, j, k, idx, nIdx, M[j][k], cntInv, mat[nIdx][idx]);
            }
        }
    }

    vec v((n + 1) * (n + 1));
    mint cntInv = mint(1) / mint(G[1].size());
    reps(i, n) { v[vert(1, i)] = (M[1][i] * cntInv); }

    debug(mat);
    debug(v);

    auto res = pow(mat, x - 1) * v;

    reps(i, n) {
        mint ans = 0;
        reps(j, n) { ans += res[vert(j, i)]; }
        cout << ans.val() << endl;
    }
}
0