結果

問題 No.3635 Probability trip
コンテスト
ユーザー yaaya
提出日時 2026-08-21 22:15:15
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 3,921 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,260 ms
コンパイル使用メモリ 348,656 KB
実行使用メモリ 9,420 KB
最終ジャッジ日時 2026-08-21 22:15:31
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 14 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define ll long long
#define ull unsigned ll
#define ld long double
#define bl __int128_t
#define fi first
#define se second
#define vel vector<ll>
#define vvel vector<vel>
#define pll pair<ll,ll>
#define vepll vector<pll>
#define vvepll vector<vepll>
#define ves vector<string>
#define vem vector<mint>
#define vvem vector<vem>
#define pmm pair<mint,mint>
#define cleout(i) cout<<fixed<<setprecision(i)
template<class T>using PQ=priority_queue<T,vector<T>,greater<T>>;
//               上  右 下 左
vector<int> di={-1, 0, 1, 0};
vector<int> dj={ 0, 1, 0,-1};

vector<int> dx={ 0, 1, 0,-1};
vector<int> dy={ 1, 0,-1, 0};


vector<int> ddx={ 1, 1, 1, 0, -1, -1, -1, 0 };
vector<int> ddy={ 1, 0, -1, -1, -1, 0, 1, 1 };

ll inf=1000000000000000000;//1e18
// LLONG_MAX

mt19937_64 rng((ull)chrono::steady_clock::now().time_since_epoch().count());

struct mint{
    ll num;
    static ll P;
    static void set_mod(ll MOD){
        P=MOD;
    }
    mint(ll x=0){
        if(x<0){
            x*=-1;
            x%=P;
            x=P-x;
        }
        x%=P;
        num=x;
    }
    mint operator+(const mint &other)const{
        return mint(num+other.num);
    }
    mint operator-(const mint &other)const{
        return mint(num-other.num);
    }
    mint operator*(const mint &other)const{
        return mint(num*other.num);
    }
    mint &operator+=(const mint &other){
        num+=other.num;
        if(num>=P) num-=P;
        return *this;
    }
    mint &operator-=(const mint &other){
        num-=other.num;
        if(num<0) num+=P;
        return *this;
    }
    mint &operator*=(const mint &other){
        num=(num*other.num)%P;
        return *this;
    }
    mint beki(const ll &x)const{
        ll pos=x;
        mint res=1;
        mint now=num;
        while(pos){
            if(pos&1){
                res*=now;
            }
            now*=now;
            pos/=2;
        }
        return res;
    }
    mint inv()const{
        mint res=1;
        mint now=num;
        rep(i,0,30){
            if((P-2)&(1ll<<i)){
                res*=now;
            } 
            now*=now;
        }
        return res;
    }
    mint operator/(const mint &other)const{
        return *this*other.inv();
    }
    mint &operator/=(const mint &other){
        num=(num*other.inv())%P;
        return *this;
    }
    operator ll()const{
        return (ll)(num);
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.num;
        return os;
    }
    friend istream& operator>>(istream& is,mint& m){
        ll x;
        is>>x;
        m=mint(x);
        return is;
    }
};
ll mint::P=998244353;
//ll mint::P=1000000007;

template<typename T,typename F>
T POW(T id,T a,ll K,F op){
    T res=id;
    while(K){
        if(1&K){
            res=op(res,a);
        }
        a=op(a,a);
        K/=2;
    }
    return res;
}

void _solve(){
    ll N,M;
    cin>>N>>M;
    vvem G(N,vem(N));
    rep(i,0,M){
        ll u,v;
        cin>>u>>v;
        u--;
        v--;
        G[u][v]=1;
        G[v][u]=1;
    }
    ll S,T,A,B;
    cin>>S>>T>>A>>B;
    S--;
    T--;
    A--;
    B--;
    vvem id(N,vem(N));
    rep(i,0,N)id[i][i]=1;
    auto mul=[&](vvem &a,vvem &b){
        vvem res(N,vem(N,0));
        rep(i,0,N){
            rep(j,0,N){
                rep(k,0,N){
                    res[i][j]+=a[i][k]*b[k][j];
                }
            }
        }
        return res;
    };
    vvem sG=POW(id,G,T,mul);
    vvem tG=POW(id,G,S-T,mul);
    mint div=0;
    rep(i,0,N){
        div+=sG[0][i]*tG[i][A];
    }
    cout<<sG[0][B]*tG[B][A]/div<<"\n";
}


int main(){
    cin.tie(nullptr);
 	ios_base::sync_with_stdio(false);

    
    ll _;
    bool multitest=0;
    if(multitest)cin>>_;
    else _=1;
    rep(__,0,_){
        _solve();
    }
}
0