//O(N^6) 解 ただし定数倍に /2^6 がついている #include using namespace std; #if __has_include() #include using namespace atcoder; #endif using ll = long long; using ld = long double; using ull = unsigned long long; #define endl "\n" typedef pair Pii; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i)) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(x) begin(x), end(x) #define PB push_back #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(s) (s).begin(),(s).end() #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define pb push_back #define P pair #define PQminll priority_queue, greater> #define PQmaxll priority_queue,less> #define PQminP priority_queue, greater

> #define PQmaxP priority_queue,less

> #define NP next_permutation typedef string::const_iterator State; class ParseError {}; //const ll mod = 1000000009; const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 4100000000000000000ll; const ld eps = ld(0.00000000000001); //static const long double pi = 3.141592653589793; templatevoid vcin(vector &n){for(int i=0;i>n[i];} templatevoid vcin(vector &n,vector &m){for(int i=0;i>n[i]>>m[i];} templatevoid vcout(vector &n){for(int i=0;ivoid vcin(vector> &n){for(int i=0;i>n[i][j];}}} templatevoid vcout(vector> &n){for(int i=0;ivoid print(T a){cout<auto min(const T& a){ return *min_element(all(a)); } templateauto max(const T& a){ return *max_element(all(a)); } templatevoid print(pair a){cout<bool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b void ifmin(T t,T u){if(t>u){cout<<-1< void ifmax(T t,T u){if(t>u){cout<<-1<>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<>= 1; } return ret; } vector divisor(ll x){ vector ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; } ll pop(ll x){return __builtin_popcountll(x);} ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;} P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;} P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});} P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});} P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});} P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});} P Pgyaku(P a){ return hyou({a.se,a.fi});} void cincout(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); } using mint = modint998244353; ll U,V; void Set(ll u,ll v){ U=u; V=v; } ll ind(ll i,ll j){ return i*(V+1)+j; } template int solve_linear_equations(vector> a,vector b,vector &res){ ll n=a.size(),m=a[0].size(); ll x=0; for(int i=0;i r; for(int i=0;i=0;i--){ ll ind=-1; for(int j=0;j>n; assert(2<=n&&n<=100); vector a(n-1),b(n-1),l(n-1); map m; ll Sum=0; map seen; for(int i=0;i>a[i]>>b[i]>>l[i]; a[i]--; b[i]--; assert(a[i]!=b[i]); if(seen[{a[i],b[i]}]) assert(false); seen[{a[i],b[i]}]=true; seen[{b[i],a[i]}]=true; assert(0<=min(a[i],b[i])&&max(a[i],b[i])<=n-1); assert(1<=l[i]&&l[i] s(n),t(n); ll u=0,v=0; for(int i=0;iv){ swap(u,v); swap(s,t); swap(x,y); } Set(u,v); mint k=u*x+v*y; mint p=n*(n-1)/2-(n-2); vector> g((u+1)*(v+1)-1,vector((u+1)*(v+1))); vector f((u+1)*(v+1)-1); for(int i=0;i<=u;i++){ for(int j=0;j<=v;j++){ if(i==u&&j==v) continue; f[ind(i,j)]=mint(-1)/mint(n); f[ind(i,j)]*=k*p; mint q=n-i-j; g[ind(i,j)][ind(i,j)]-=1; g[ind(i,j)][ind(i,j)]*=k*p; g[ind(i,j)][ind(i,j)]+=q*x*i; if(i) g[ind(i,j)][ind(i-1,j)]+=(p-q)*x*i; g[ind(i,j)][ind(i,j)]+=q*y*j; if(j) g[ind(i,j)][ind(i,j-1)]+=(p-q)*y*j; if(i!=u) g[ind(i,j)][ind(i+1,j)]+=(q-1)*x*(u-i); g[ind(i,j)][ind(i,j)]+=(p-q+1)*x*(u-i); if(j!=v) g[ind(i,j)][ind(i,j+1)]+=(q-1)*y*(v-j); g[ind(i,j)][ind(i,j)]+=(p-q+1)*y*(v-j); } } vector res; int check=solve_linear_equations(g,f,res); assert(check!=-1); mint ans=0; for(int i=0;i